Skip to content

Commit

Permalink
Merge pull request #269 from rjarry/blacklist
Browse files Browse the repository at this point in the history
Affinity mapping fixes
  • Loading branch information
nhorman committed Jul 13, 2023
2 parents 4efc192 + eee7917 commit 8b23bda
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
39 changes: 32 additions & 7 deletions activate.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
* of interrupts to the kernel.
*/
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>

#include "irqbalance.h"

Expand All @@ -48,7 +50,7 @@ static void activate_mapping(struct irq_info *info, void *data __attribute__((un
{
char buf[PATH_MAX];
FILE *file;
int ret = 0;
int errsave, ret;
cpumask_t applied_mask;

/*
Expand All @@ -60,6 +62,9 @@ static void activate_mapping(struct irq_info *info, void *data __attribute__((un
if (!info->assigned_obj)
return;

if (info->flags & IRQ_FLAG_AFFINITY_UNMANAGED)
return;

/* activate only online cpus, otherwise writing to procfs returns EOVERFLOW */
cpus_and(applied_mask, cpu_online_map, info->assigned_obj->mask);

Expand All @@ -72,17 +77,37 @@ static void activate_mapping(struct irq_info *info, void *data __attribute__((un
sprintf(buf, "/proc/irq/%i/smp_affinity", info->irq);
file = fopen(buf, "w");
if (!file)
return;
goto error;

cpumask_scnprintf(buf, PATH_MAX, applied_mask);
ret = fprintf(file, "%s", buf);
if (ret < 0) {
log(TO_ALL, LOG_WARNING, "cannot change irq %i's affinity, add it to banned list", info->irq);
add_banned_irq(info->irq);
remove_one_irq_from_db(info->irq);
errsave = errno;
if (fclose(file)) {
errsave = errno;
goto error;
}
fclose(file);
if (ret < 0)
goto error;
info->moved = 0; /*migration is done*/
error:
log(TO_ALL, LOG_WARNING,
"Cannot change IRQ %i affinity: %s\n",
info->irq, strerror(errsave));
switch (errsave) {
case ENOSPC: /* Specified CPU APIC is full. */
case EAGAIN: /* Interrupted by signal. */
case EBUSY: /* Affinity change already in progress. */
case EINVAL: /* IRQ would be bound to no CPU. */
case ERANGE: /* CPU in mask is offline. */
case ENOMEM: /* Kernel cannot allocate CPU mask. */
/* Do not blacklist the IRQ on transient errors. */
break;
default:
/* Any other error is considered permanent. */
info->flags |= IRQ_FLAG_AFFINITY_UNMANAGED;
log(TO_ALL, LOG_WARNING, "IRQ %i affinity is now unmanaged\n",
info->irq);
}
}

void activate_mappings(void)
Expand Down
28 changes: 3 additions & 25 deletions classify.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static gint compare_ints(gconstpointer a, gconstpointer b)
return ai->irq - bi->irq;
}

static void __add_banned_irq(int irq, GList **list)
static void add_banned_irq(int irq, GList **list)
{
struct irq_info find, *new;
GList *entry;
Expand All @@ -281,14 +281,9 @@ static void __add_banned_irq(int irq, GList **list)
return;
}

void add_banned_irq(int irq)
{
__add_banned_irq(irq, &banned_irqs);
}

void add_cl_banned_irq(int irq)
{
__add_banned_irq(irq, &cl_banned_irqs);
add_banned_irq(irq, &cl_banned_irqs);
}

gint substr_find(gconstpointer a, gconstpointer b)
Expand Down Expand Up @@ -392,23 +387,6 @@ static struct irq_info *add_one_irq_to_db(const char *devpath, struct irq_info *
return new;
}

void remove_one_irq_from_db(int irq)
{
struct irq_info find, *tmp;
GList *entry = NULL;

find.irq = irq;
entry = g_list_find_custom(interrupts_db, &find, compare_ints);
if (!entry)
return;

tmp = entry->data;
interrupts_db = g_list_remove(interrupts_db, tmp);
free(tmp);
log(TO_CONSOLE, LOG_INFO, "IRQ %d was removed from db.\n", irq);
return;
}

static void parse_user_policy_key(char *buf, int irq, struct user_irq_policy *pol)
{
char *key, *value, *end;
Expand Down Expand Up @@ -629,7 +607,7 @@ static void add_new_irq(char *path, struct irq_info *hint)
/* Set NULL devpath for the irq has no sysfs entries */
get_irq_user_policy(path, irq, &pol);
if ((pol.ban == 1) || check_for_irq_ban(hint, mod)) { /*FIXME*/
__add_banned_irq(irq, &banned_irqs);
add_banned_irq(irq, &banned_irqs);
new = get_irq_info(irq);
} else
new = add_one_irq_to_db(path, hint, &pol);
Expand Down
2 changes: 0 additions & 2 deletions irqbalance.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ extern struct irq_info *get_irq_info(int irq);
extern void migrate_irq(GList **from, GList **to, struct irq_info *info);
extern void free_cl_opts(void);
extern void add_cl_banned_module(char *modname);
extern void add_banned_irq(int irq);
extern void remove_one_irq_from_db(int irq);
#define irq_numa_node(irq) ((irq)->numa_node)


Expand Down
3 changes: 2 additions & 1 deletion types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
/*
* IRQ Internal tracking flags
*/
#define IRQ_FLAG_BANNED 1
#define IRQ_FLAG_BANNED (1ULL << 0)
#define IRQ_FLAG_AFFINITY_UNMANAGED (1ULL << 1)

enum obj_type_e {
OBJ_TYPE_CPU,
Expand Down

0 comments on commit 8b23bda

Please sign in to comment.