Index: usr.bin/cpuset/cpuset.c =================================================================== RCS file: /home/ncvs/src/usr.bin/cpuset/cpuset.c,v retrieving revision 1.4 diff -u -r1.4 cpuset.c --- usr.bin/cpuset/cpuset.c 12 Mar 2008 23:54:40 -0000 1.4 +++ usr.bin/cpuset/cpuset.c 11 Apr 2008 03:22:09 -0000 @@ -2,6 +2,9 @@ * Copyright (c) 2007, 2008 Jeffrey Roberson * All rights reserved. * + * Copyright (c) 2008 Nokia Corporation + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -51,6 +54,7 @@ int rflag; int sflag; int tflag; +int xflag; id_t id; cpulevel_t level; cpuwhich_t which; @@ -149,7 +153,7 @@ printf("\n"); } -const char *whichnames[] = { NULL, "tid", "pid", "cpuset" }; +const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq" }; const char *levelnames[] = { NULL, " root", " cpuset", "" }; static void @@ -194,7 +198,7 @@ level = CPU_LEVEL_WHICH; which = CPU_WHICH_PID; id = pid = tid = setid = -1; - while ((ch = getopt(argc, argv, "cgil:p:rs:t:")) != -1) { + while ((ch = getopt(argc, argv, "cgil:p:rs:t:x:")) != -1) { switch (ch) { case 'c': if (rflag) @@ -233,6 +237,11 @@ which = CPU_WHICH_TID; id = tid = atoi(optarg); break; + case 'x': + xflag = 1; + which = CPU_WHICH_IRQ; + id = atoi(optarg); + break; default: usage(); } @@ -243,7 +252,7 @@ if (argc || lflag) usage(); /* Only one identity specifier. */ - if (sflag + pflag + tflag > 1) + if (xflag + sflag + pflag + tflag > 1) usage(); if (iflag) printsetid(); @@ -257,7 +266,7 @@ * The user wants to run a command with a set and possibly cpumask. */ if (argc) { - if (pflag | rflag | tflag) + if (pflag | rflag | tflag | xflag) usage(); if (sflag) { if (cpuset_setid(CPU_WHICH_PID, -1, setid)) @@ -283,7 +292,10 @@ if (!lflag && !sflag) usage(); /* You can only set a mask on a thread. */ - if (tflag && (sflag || pflag)) + if (tflag && (sflag | pflag | xflag)) + usage(); + /* You can only set a mask on an irq. */ + if (xflag && (pflag | sflag | tflag)) usage(); if (pflag && sflag) { if (cpuset_setid(CPU_WHICH_PID, pid, setid)) @@ -313,8 +325,8 @@ fprintf(stderr, " cpuset [-l cpu-list] [-s setid] -p pid\n"); fprintf(stderr, - " cpuset [-cr] [-l cpu-list] [-p pid | -t tid | -s setid]\n"); + " cpuset [-cr] [-l cpu-list] [-p pid | -t tid | -s setid | -x irq]\n"); fprintf(stderr, - " cpuset [-cgir] [-p pid | -t tid | -s setid]\n"); + " cpuset [-cgir] [-p pid | -t tid | -s setid | -x irq]\n"); exit(1); } Index: sys/amd64/amd64/intr_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/amd64/amd64/intr_machdep.c,v retrieving revision 1.40 diff -u -r1.40 intr_machdep.c --- sys/amd64/amd64/intr_machdep.c 5 Apr 2008 19:58:28 -0000 1.40 +++ sys/amd64/amd64/intr_machdep.c 11 Apr 2008 03:22:09 -0000 @@ -139,7 +139,7 @@ vector = isrc->is_pic->pic_vector(isrc); if (interrupt_sources[vector] != NULL) return (EEXIST); - error = intr_event_create(&isrc->is_event, isrc, 0, + error = intr_event_create(&isrc->is_event, isrc, 0, vector, intr_disable_src, (mask_fn)isrc->is_pic->pic_enable_source, (mask_fn)isrc->is_pic->pic_eoi_source, intr_assign_cpu, "irq%d:", vector); Index: sys/amd64/conf/GENERIC =================================================================== RCS file: /home/ncvs/src/sys/amd64/conf/GENERIC,v retrieving revision 1.495 diff -u -r1.495 GENERIC --- sys/amd64/conf/GENERIC 27 Mar 2008 11:54:17 -0000 1.495 +++ sys/amd64/conf/GENERIC 11 Apr 2008 03:22:09 -0000 @@ -73,6 +73,7 @@ options INVARIANT_SUPPORT # Extra sanity checks of internal structures, required by INVARIANTS options WITNESS # Enable checks to detect deadlocks and cycles options WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed +options ALT_BREAK_TO_DEBUGGER # Make an SMP-capable kernel by default options SMP # Symmetric MultiProcessor Kernel Index: sys/arm/arm/intr.c =================================================================== RCS file: /home/ncvs/src/sys/arm/arm/intr.c,v retrieving revision 1.20 diff -u -r1.20 intr.c --- sys/arm/arm/intr.c 5 Apr 2008 19:58:28 -0000 1.20 +++ sys/arm/arm/intr.c 11 Apr 2008 03:22:09 -0000 @@ -70,7 +70,7 @@ return; event = intr_events[irq]; if (event == NULL) { - error = intr_event_create(&event, (void *)irq, 0, + error = intr_event_create(&event, (void *)irq, 0, irq, (mask_fn)arm_mask_irq, (mask_fn)arm_unmask_irq, NULL, NULL, "intr%d:", irq); if (error) Index: sys/i386/i386/intr_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/intr_machdep.c,v retrieving revision 1.35 diff -u -r1.35 intr_machdep.c --- sys/i386/i386/intr_machdep.c 5 Apr 2008 19:58:29 -0000 1.35 +++ sys/i386/i386/intr_machdep.c 11 Apr 2008 03:22:12 -0000 @@ -130,7 +130,7 @@ vector = isrc->is_pic->pic_vector(isrc); if (interrupt_sources[vector] != NULL) return (EEXIST); - error = intr_event_create(&isrc->is_event, isrc, 0, + error = intr_event_create(&isrc->is_event, isrc, 0, vector, intr_disable_src, (mask_fn)isrc->is_pic->pic_enable_source, (mask_fn)isrc->is_pic->pic_eoi_source, intr_assign_cpu, "irq%d:", vector); Index: sys/ia64/ia64/interrupt.c =================================================================== RCS file: /home/ncvs/src/sys/ia64/ia64/interrupt.c,v retrieving revision 1.65 diff -u -r1.65 interrupt.c --- sys/ia64/ia64/interrupt.c 5 Apr 2008 19:58:29 -0000 1.65 +++ sys/ia64/ia64/interrupt.c 11 Apr 2008 03:22:12 -0000 @@ -340,7 +340,7 @@ return (ENOMEM); error = intr_event_create(&i->event, (void *)(uintptr_t)vector, - 0, ia64_intr_mask, ia64_intr_unmask, ia64_intr_eoi, + 0, vector, ia64_intr_mask, ia64_intr_unmask, ia64_intr_eoi, NULL, "irq%u:", irq); if (error) { free(i, M_DEVBUF); Index: sys/kern/kern_cpuset.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_cpuset.c,v retrieving revision 1.8 diff -u -r1.8 kern_cpuset.c --- sys/kern/kern_cpuset.c 4 Apr 2008 01:22:04 -0000 1.8 +++ sys/kern/kern_cpuset.c 11 Apr 2008 03:22:12 -0000 @@ -412,6 +412,8 @@ return (0); } return (ESRCH); + case CPU_WHICH_IRQ: + return (0); default: return (EINVAL); } @@ -760,6 +762,8 @@ break; case CPU_WHICH_CPUSET: break; + case CPU_WHICH_IRQ: + return (EINVAL); } switch (uap->level) { case CPU_LEVEL_ROOT: @@ -820,6 +824,9 @@ break; case CPU_WHICH_CPUSET: break; + case CPU_WHICH_IRQ: + error = EINVAL; + goto out; } if (uap->level == CPU_LEVEL_ROOT) nset = cpuset_refroot(set); @@ -845,6 +852,9 @@ case CPU_WHICH_CPUSET: CPU_COPY(&set->cs_mask, mask); break; + case CPU_WHICH_IRQ: + error = intr_getaffinity(uap->id, mask); + break; } break; default: @@ -921,6 +931,9 @@ break; case CPU_WHICH_CPUSET: break; + case CPU_WHICH_IRQ: + error = EINVAL; + goto out; } if (uap->level == CPU_LEVEL_ROOT) nset = cpuset_refroot(set); @@ -946,6 +959,9 @@ cpuset_rel(set); } break; + case CPU_WHICH_IRQ: + error = intr_setaffinity(uap->id, mask); + break; default: error = EINVAL; break; Index: sys/kern/kern_intr.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_intr.c,v retrieving revision 1.161 diff -u -r1.161 kern_intr.c --- sys/kern/kern_intr.c 5 Apr 2008 20:13:15 -0000 1.161 +++ sys/kern/kern_intr.c 11 Apr 2008 03:22:12 -0000 @@ -28,11 +28,11 @@ __FBSDID("$FreeBSD: src/sys/kern/kern_intr.c,v 1.161 2008/04/05 20:13:15 jhb Exp $"); #include "opt_ddb.h" -#include "opt_intr_filter.h" #include #include #include +#include #include #include #include @@ -92,6 +92,8 @@ "Number of consecutive interrupts before storm protection is enabled"); static TAILQ_HEAD(, intr_event) event_list = TAILQ_HEAD_INITIALIZER(event_list); +static struct mtx event_lock; +MTX_SYSINIT(intr_event_list, &event_lock, "intr event list", MTX_DEF); static void intr_event_update(struct intr_event *ie); #ifdef INTR_FILTER @@ -244,7 +246,7 @@ } int -intr_event_create(struct intr_event **event, void *source,int flags, +intr_event_create(struct intr_event **event, void *source,int flags, int irq, void (*pre_ithread)(void *), void (*post_ithread)(void *), void (*post_filter)(void *), int (*assign_cpu)(void *, u_char), const char *fmt, ...) @@ -262,6 +264,7 @@ ie->ie_post_filter = post_filter; ie->ie_assign_cpu = assign_cpu; ie->ie_flags = flags; + ie->ie_irq = irq; ie->ie_cpu = NOCPU; TAILQ_INIT(&ie->ie_handlers); mtx_init(&ie->ie_lock, "intr event", NULL, MTX_DEF); @@ -270,9 +273,9 @@ vsnprintf(ie->ie_name, sizeof(ie->ie_name), fmt, ap); va_end(ap); strlcpy(ie->ie_fullname, ie->ie_name, sizeof(ie->ie_fullname)); - mtx_pool_lock(mtxpool_sleep, &event_list); + mtx_lock(&event_lock); TAILQ_INSERT_TAIL(&event_list, ie, ie_list); - mtx_pool_unlock(mtxpool_sleep, &event_list); + mtx_unlock(&event_lock); if (event != NULL) *event = ie; CTR2(KTR_INTR, "%s: created %s", __func__, ie->ie_name); @@ -290,7 +293,8 @@ int intr_event_bind(struct intr_event *ie, u_char cpu) { - struct thread *td; + cpuset_t mask; + lwpid_t id; int error; /* Need a CPU to bind to. */ @@ -299,28 +303,97 @@ if (ie->ie_assign_cpu == NULL) return (EOPNOTSUPP); - - /* Don't allow a bind request if the interrupt is already bound. */ + /* + * If we have any ithreads try to set their mask first since this + * can fail. + */ mtx_lock(&ie->ie_lock); - if (ie->ie_cpu != NOCPU && cpu != NOCPU) { + if (ie->ie_thread != NULL) { + CPU_ZERO(&mask); + if (cpu == NOCPU) + CPU_COPY(cpuset_root, &mask); + else + CPU_SET(cpu, &mask); + id = ie->ie_thread->it_thread->td_tid; + mtx_unlock(&ie->ie_lock); + error = cpuset_setthread(id, &mask); + if (error) + return (error); + } else mtx_unlock(&ie->ie_lock); - return (EBUSY); - } - mtx_unlock(&ie->ie_lock); - error = ie->ie_assign_cpu(ie->ie_source, cpu); if (error) return (error); mtx_lock(&ie->ie_lock); - if (ie->ie_thread != NULL) - td = ie->ie_thread->it_thread; - else - td = NULL; - if (td != NULL) - thread_lock(td); ie->ie_cpu = cpu; - if (td != NULL) - thread_unlock(td); + mtx_unlock(&ie->ie_lock); + + return (error); +} + +static struct intr_event * +intr_lookup(int irq) +{ + struct intr_event *ie; + + mtx_lock(&event_lock); + TAILQ_FOREACH(ie, &event_list, ie_list) + if (ie->ie_irq == irq && + (ie->ie_flags & IE_SOFT) == 0 && + TAILQ_FIRST(&ie->ie_handlers) != NULL) + break; + mtx_unlock(&event_lock); + return (ie); +} + +int +intr_setaffinity(int irq, void *m) +{ + struct intr_event *ie; + cpuset_t *mask; + u_char cpu; + int error; + int n; + + mask = m; + error = 0; + cpu = NOCPU; + /* + * If we're setting all cpus we can unbind. Otherwise make sure + * only one cpu is in the set. + */ + if (CPU_CMP(cpuset_root, mask)) { + for (n = 0; n < CPU_SETSIZE; n++) { + if (!CPU_ISSET(n, mask)) + continue; + if (cpu != NOCPU) + return (EINVAL); + cpu = (u_char)n; + } + } + ie = intr_lookup(irq); + if (ie == NULL) + return (ESRCH); + intr_event_bind(ie, cpu); + return (error); +} + +int +intr_getaffinity(int irq, void *m) +{ + struct intr_event *ie; + cpuset_t *mask; + + mask = m; + ie = intr_lookup(irq); + if (ie == NULL) + return (ESRCH); + CPU_ZERO(mask); + mtx_lock(&ie->ie_lock); + if (ie->ie_cpu == NOCPU) + CPU_COPY(cpuset_root, mask); + else + CPU_SET(ie->ie_cpu, mask); mtx_unlock(&ie->ie_lock); return (0); } @@ -329,14 +402,14 @@ intr_event_destroy(struct intr_event *ie) { + mtx_lock(&event_lock); mtx_lock(&ie->ie_lock); if (!TAILQ_EMPTY(&ie->ie_handlers)) { mtx_unlock(&ie->ie_lock); + mtx_unlock(&event_lock); return (EBUSY); } - mtx_pool_lock(mtxpool_sleep, &event_list); TAILQ_REMOVE(&event_list, ie, ie_list); - mtx_pool_unlock(mtxpool_sleep, &event_list); #ifndef notyet if (ie->ie_thread != NULL) { ithread_destroy(ie->ie_thread); @@ -344,6 +417,7 @@ } #endif mtx_unlock(&ie->ie_lock); + mtx_unlock(&event_lock); mtx_destroy(&ie->ie_lock); free(ie, M_ITHREAD); return (0); @@ -914,7 +988,7 @@ if (!(ie->ie_flags & IE_SOFT)) return (EINVAL); } else { - error = intr_event_create(&ie, NULL, IE_SOFT, + error = intr_event_create(&ie, NULL, IE_SOFT, 0, NULL, NULL, NULL, NULL, "swi%d:", pri); if (error) return (error); @@ -1106,7 +1180,6 @@ struct intr_event *ie; struct thread *td; struct proc *p; - u_char cpu; td = curthread; p = td->td_proc; @@ -1115,7 +1188,6 @@ ("%s: ithread and proc linkage out of sync", __func__)); ie = ithd->it_event; ie->ie_count = 0; - cpu = NOCPU; /* * As long as we have interrupts outstanding, go through the @@ -1161,21 +1233,6 @@ ie->ie_count = 0; mi_switch(SW_VOL, NULL); } - -#ifdef SMP - /* - * Ensure we are bound to the correct CPU. We can't - * move ithreads until SMP is running however, so just - * leave interrupts on the boor CPU during boot. - */ - if (ie->ie_cpu != cpu && smp_started) { - cpu = ie->ie_cpu; - if (cpu == NOCPU) - sched_unbind(td); - else - sched_bind(td, cpu); - } -#endif thread_unlock(td); } } @@ -1276,7 +1333,6 @@ struct thread *td; struct proc *p; int priv; - u_char cpu; td = curthread; p = td->td_proc; @@ -1287,7 +1343,6 @@ ("%s: ithread and proc linkage out of sync", __func__)); ie = ithd->it_event; ie->ie_count = 0; - cpu = NOCPU; /* * As long as we have interrupts outstanding, go through the @@ -1336,21 +1391,6 @@ ie->ie_count = 0; mi_switch(SW_VOL, NULL); } - -#ifdef SMP - /* - * Ensure we are bound to the correct CPU. We can't - * move ithreads until SMP is running however, so just - * leave interrupts on the boor CPU during boot. - */ - if (!priv && ie->ie_cpu != cpu && smp_started) { - cpu = ie->ie_cpu; - if (cpu == NOCPU) - sched_unbind(td); - else - sched_bind(td, cpu); - } -#endif thread_unlock(td); } } @@ -1580,8 +1620,6 @@ db_printf("(pid %d)", it->it_thread->td_proc->p_pid); else db_printf("(no thread)"); - if (ie->ie_cpu != NOCPU) - db_printf(" (CPU %d)", ie->ie_cpu); if ((ie->ie_flags & (IE_SOFT | IE_ENTROPY | IE_ADDING_THREAD)) != 0 || (it != NULL && it->it_need)) { db_printf(" {"); Index: sys/powerpc/powerpc/intr_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/powerpc/powerpc/intr_machdep.c,v retrieving revision 1.20 diff -u -r1.20 intr_machdep.c --- sys/powerpc/powerpc/intr_machdep.c 5 Apr 2008 19:58:29 -0000 1.20 +++ sys/powerpc/powerpc/intr_machdep.c 11 Apr 2008 03:22:16 -0000 @@ -226,7 +226,7 @@ return (ENOMEM); if (i->event == NULL) { - error = intr_event_create(&i->event, (void *)irq, 0, + error = intr_event_create(&i->event, (void *)irq, 0, irq, powerpc_intr_mask, powerpc_intr_unmask, powerpc_intr_eoi, NULL, "irq%u:", irq); if (error) Index: sys/sparc64/sparc64/intr_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/sparc64/sparc64/intr_machdep.c,v retrieving revision 1.32 diff -u -r1.32 intr_machdep.c --- sys/sparc64/sparc64/intr_machdep.c 9 Apr 2008 21:14:01 -0000 1.32 +++ sys/sparc64/sparc64/intr_machdep.c 11 Apr 2008 03:22:16 -0000 @@ -282,7 +282,7 @@ * CPU as long as the source of a level sensitive interrupt is * not cleared. */ - error = intr_event_create(&ie, iv, 0, NULL, intr_enable_eoi, + error = intr_event_create(&ie, iv, 0, vec, NULL, intr_enable_eoi, intr_enable_eoi, NULL, "vec%d:", vec); if (error != 0) return (error); Index: sys/sun4v/sun4v/intr_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/sun4v/sun4v/intr_machdep.c,v retrieving revision 1.10 diff -u -r1.10 intr_machdep.c --- sys/sun4v/sun4v/intr_machdep.c 5 Apr 2008 19:58:29 -0000 1.10 +++ sys/sun4v/sun4v/intr_machdep.c 11 Apr 2008 03:22:16 -0000 @@ -307,8 +307,8 @@ ie = iv->iv_event; mtx_unlock_spin(&intr_table_lock); if (ie == NULL) { - errcode = intr_event_create(&ie, (void *)(intptr_t)vec, 0, NULL, - intr_enable, intr_enable, NULL, "vec%d:", vec); + errcode = intr_event_create(&ie, (void *)(intptr_t)vec, 0, vec, + NULL, intr_enable, intr_enable, NULL, "vec%d:", vec); if (errcode) return (errcode); mtx_lock_spin(&intr_table_lock); Index: sys/sys/cpuset.h =================================================================== RCS file: /home/ncvs/src/sys/sys/cpuset.h,v retrieving revision 1.6 diff -u -r1.6 cpuset.h --- sys/sys/cpuset.h 4 Apr 2008 01:22:04 -0000 1.6 +++ sys/sys/cpuset.h 11 Apr 2008 03:22:16 -0000 @@ -131,6 +131,7 @@ #define CPU_WHICH_TID 1 /* Specifies a thread id. */ #define CPU_WHICH_PID 2 /* Specifies a process id. */ #define CPU_WHICH_CPUSET 3 /* Specifies a set id. */ +#define CPU_WHICH_IRQ 4 /* Specifies an irq #. */ /* * Reserved cpuset identifiers. Index: sys/sys/interrupt.h =================================================================== RCS file: /home/ncvs/src/sys/sys/interrupt.h,v retrieving revision 1.40 diff -u -r1.40 interrupt.h --- sys/sys/interrupt.h 5 Apr 2008 19:58:30 -0000 1.40 +++ sys/sys/interrupt.h 11 Apr 2008 03:22:16 -0000 @@ -107,6 +107,7 @@ int ie_count; /* Loop counter. */ int ie_warncnt; /* Rate-check interrupt storm warns. */ struct timeval ie_warntm; + int ie_irq; /* Physical irq number if !SOFT. */ u_char ie_cpu; /* CPU this event is bound to. */ }; @@ -151,14 +152,16 @@ u_char pri, enum intr_type flags, void **cookiep); int intr_event_bind(struct intr_event *ie, u_char cpu); int intr_event_create(struct intr_event **event, void *source, - int flags, void (*pre_ithread)(void *), + int flags, int irq, void (*pre_ithread)(void *), void (*post_ithread)(void *), void (*post_filter)(void *), int (*assign_cpu)(void *, u_char), const char *fmt, ...) - __printflike(8, 9); + __printflike(9, 10); int intr_event_destroy(struct intr_event *ie); int intr_event_handle(struct intr_event *ie, struct trapframe *frame); int intr_event_remove_handler(void *cookie); +int intr_getaffinity(int irq, void *mask); void *intr_handler_source(void *cookie); +int intr_setaffinity(int irq, void *mask); int swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler, void *arg, int pri, enum intr_type flags, void **cookiep);