Deleted Added
full compact
subr_taskqueue.c (301208) subr_taskqueue.c (302372)
1/*-
2 * Copyright (c) 2000 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2000 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/kern/subr_taskqueue.c 301208 2016-06-02 15:52:34Z mjg $");
28__FBSDID("$FreeBSD: head/sys/kern/subr_taskqueue.c 302372 2016-07-06 14:09:49Z nwhitehorn $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/cpuset.h>
34#include <sys/interrupt.h>
35#include <sys/kernel.h>
36#include <sys/kthread.h>

--- 790 unchanged lines hidden (view full) ---

827 struct task bt_task;
828 int bt_cpuid;
829};
830
831static void
832taskqgroup_cpu_create(struct taskqgroup *qgroup, int idx)
833{
834 struct taskqgroup_cpu *qcpu;
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/cpuset.h>
34#include <sys/interrupt.h>
35#include <sys/kernel.h>
36#include <sys/kthread.h>

--- 790 unchanged lines hidden (view full) ---

827 struct task bt_task;
828 int bt_cpuid;
829};
830
831static void
832taskqgroup_cpu_create(struct taskqgroup *qgroup, int idx)
833{
834 struct taskqgroup_cpu *qcpu;
835 int i, j;
835
836 qcpu = &qgroup->tqg_queue[idx];
837 LIST_INIT(&qcpu->tgc_tasks);
838 qcpu->tgc_taskq = taskqueue_create_fast(NULL, M_WAITOK,
839 taskqueue_thread_enqueue, &qcpu->tgc_taskq);
840 taskqueue_start_threads(&qcpu->tgc_taskq, 1, PI_SOFT,
841 "%s_%d", qgroup->tqg_name, idx);
836
837 qcpu = &qgroup->tqg_queue[idx];
838 LIST_INIT(&qcpu->tgc_tasks);
839 qcpu->tgc_taskq = taskqueue_create_fast(NULL, M_WAITOK,
840 taskqueue_thread_enqueue, &qcpu->tgc_taskq);
841 taskqueue_start_threads(&qcpu->tgc_taskq, 1, PI_SOFT,
842 "%s_%d", qgroup->tqg_name, idx);
842 qcpu->tgc_cpu = idx * qgroup->tqg_stride;
843
844 for (i = CPU_FIRST(), j = 0; j < idx * qgroup->tqg_stride;
845 j++, i = CPU_NEXT(i)) {
846 /*
847 * Wait: evaluate the idx * qgroup->tqg_stride'th CPU,
848 * potentially wrapping the actual count
849 */
850 }
851 qcpu->tgc_cpu = i;
843}
844
845static void
846taskqgroup_cpu_remove(struct taskqgroup *qgroup, int idx)
847{
848
849 taskqueue_free(qgroup->tqg_queue[idx].tgc_taskq);
850}

--- 161 unchanged lines hidden (view full) ---

1012}
1013
1014static int
1015_taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride)
1016{
1017 LIST_HEAD(, grouptask) gtask_head = LIST_HEAD_INITIALIZER(NULL);
1018 cpuset_t mask;
1019 struct grouptask *gtask;
852}
853
854static void
855taskqgroup_cpu_remove(struct taskqgroup *qgroup, int idx)
856{
857
858 taskqueue_free(qgroup->tqg_queue[idx].tgc_taskq);
859}

--- 161 unchanged lines hidden (view full) ---

1021}
1022
1023static int
1024_taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride)
1025{
1026 LIST_HEAD(, grouptask) gtask_head = LIST_HEAD_INITIALIZER(NULL);
1027 cpuset_t mask;
1028 struct grouptask *gtask;
1020 int i, old_cnt, qid;
1029 int i, k, old_cnt, qid, cpu;
1021
1022 mtx_assert(&qgroup->tqg_lock, MA_OWNED);
1023
1024 if (cnt < 1 || cnt * stride > mp_ncpus || !smp_started) {
1030
1031 mtx_assert(&qgroup->tqg_lock, MA_OWNED);
1032
1033 if (cnt < 1 || cnt * stride > mp_ncpus || !smp_started) {
1025 printf("taskqgroup_adjust failed cnt: %d stride: %d mp_ncpus: %d smp_started: %d\n",
1026 cnt, stride, mp_ncpus, smp_started);
1034 printf("taskqgroup_adjust failed cnt: %d stride: %d "
1035 "mp_ncpus: %d smp_started: %d\n", cnt, stride, mp_ncpus,
1036 smp_started);
1027 return (EINVAL);
1028 }
1029 if (qgroup->tqg_adjusting) {
1030 printf("taskqgroup_adjust failed: adjusting\n");
1031 return (EBUSY);
1032 }
1033 qgroup->tqg_adjusting = 1;
1034 old_cnt = qgroup->tqg_cnt;

--- 41 unchanged lines hidden (view full) ---

1076 qgroup->tqg_queue[qid].tgc_cnt++;
1077 LIST_INSERT_HEAD(&qgroup->tqg_queue[qid].tgc_tasks, gtask,
1078 gt_list);
1079 gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq;
1080 }
1081 /*
1082 * Set new CPU and IRQ affinity
1083 */
1037 return (EINVAL);
1038 }
1039 if (qgroup->tqg_adjusting) {
1040 printf("taskqgroup_adjust failed: adjusting\n");
1041 return (EBUSY);
1042 }
1043 qgroup->tqg_adjusting = 1;
1044 old_cnt = qgroup->tqg_cnt;

--- 41 unchanged lines hidden (view full) ---

1086 qgroup->tqg_queue[qid].tgc_cnt++;
1087 LIST_INSERT_HEAD(&qgroup->tqg_queue[qid].tgc_tasks, gtask,
1088 gt_list);
1089 gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq;
1090 }
1091 /*
1092 * Set new CPU and IRQ affinity
1093 */
1094 cpu = CPU_FIRST();
1084 for (i = 0; i < cnt; i++) {
1095 for (i = 0; i < cnt; i++) {
1085 qgroup->tqg_queue[i].tgc_cpu = i * qgroup->tqg_stride;
1096 qgroup->tqg_queue[i].tgc_cpu = cpu;
1097 for (k = 0; k < qgroup->tqg_stride; k++)
1098 cpu = CPU_NEXT(cpu);
1086 CPU_ZERO(&mask);
1087 CPU_SET(qgroup->tqg_queue[i].tgc_cpu, &mask);
1088 LIST_FOREACH(gtask, &qgroup->tqg_queue[i].tgc_tasks, gt_list) {
1089 if (gtask->gt_irq == -1)
1090 continue;
1091 intr_setaffinity(gtask->gt_irq, &mask);
1092 }
1093 }

--- 46 unchanged lines hidden ---
1099 CPU_ZERO(&mask);
1100 CPU_SET(qgroup->tqg_queue[i].tgc_cpu, &mask);
1101 LIST_FOREACH(gtask, &qgroup->tqg_queue[i].tgc_tasks, gt_list) {
1102 if (gtask->gt_irq == -1)
1103 continue;
1104 intr_setaffinity(gtask->gt_irq, &mask);
1105 }
1106 }

--- 46 unchanged lines hidden ---