1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* Copyright (c) 2015, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <odp_posix_extensions.h>
#include <sched.h>
#include <pthread.h>
#include <odp/api/cpumask.h>
#include <odp_debug_internal.h>
int odp_cpumask_default_worker(odp_cpumask_t *mask, int num)
{
odp_cpumask_t overlap;
int cpu, i;
/*
* If no user supplied number or it's too large, then attempt
* to use all CPUs
*/
cpu = odp_cpumask_count(&odp_global_data.worker_cpus);
if (0 == num || cpu < num)
num = cpu;
/* build the mask, allocating down from highest numbered CPU */
odp_cpumask_zero(mask);
for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
if (odp_cpumask_isset(&odp_global_data.worker_cpus, i)) {
odp_cpumask_set(mask, i);
cpu++;
}
}
odp_cpumask_and(&overlap, mask, &odp_global_data.control_cpus);
if (odp_cpumask_count(&overlap))
ODP_DBG("\n\tWorker CPUs overlap with control CPUs...\n"
"\tthis will likely have a performance impact on the worker threads.\n");
return cpu;
}
int odp_cpumask_default_control(odp_cpumask_t *mask, int num)
{
odp_cpumask_t overlap;
int cpu, i;
/*
* If no user supplied number then default to one control CPU.
*/
if (0 == num) {
num = 1;
} else {
/*
* If user supplied number is too large, then attempt
* to use all installed control CPUs
*/
cpu = odp_cpumask_count(&odp_global_data.control_cpus);
if (cpu < num)
num = cpu;
}
/* build the mask, allocating upwards from lowest numbered CPU */
odp_cpumask_zero(mask);
for (cpu = 0, i = 0; i < CPU_SETSIZE && cpu < num; i++) {
if (odp_cpumask_isset(&odp_global_data.control_cpus, i)) {
odp_cpumask_set(mask, i);
cpu++;
}
}
odp_cpumask_and(&overlap, mask, &odp_global_data.worker_cpus);
if (odp_cpumask_count(&overlap))
ODP_DBG("\n\tControl CPUs overlap with worker CPUs...\n"
"\tthis will likely have a performance impact on the worker threads.\n");
return cpu;
}
int odp_cpumask_all_available(odp_cpumask_t *mask)
{
odp_cpumask_or(mask, &odp_global_data.worker_cpus,
&odp_global_data.control_cpus);
return odp_cpumask_count(mask);
}
|