|
|
@ -54,14 +54,15 @@ |
|
|
|
to run on all cores). |
|
|
|
to run on all cores). |
|
|
|
4) Each thread checks what core it is running on, and marks that core |
|
|
|
4) Each thread checks what core it is running on, and marks that core |
|
|
|
as "used" in the test. |
|
|
|
as "used" in the test. |
|
|
|
5) Check that all cores were "used" |
|
|
|
5) Count number of "used" cores. |
|
|
|
|
|
|
|
|
|
|
|
The test will fail if: |
|
|
|
The test will fail if: |
|
|
|
1) gpr_cpu_num_cores() == 0 |
|
|
|
1) gpr_cpu_num_cores() == 0 |
|
|
|
2) The result of gpr_cpu_current_cpu() >= gpr_cpu_num_cores() |
|
|
|
2) Any result from gpr_cpu_current_cpu() >= gpr_cpu_num_cores() |
|
|
|
3) Not all cores are used/seen in the test. If a system does not exhibit |
|
|
|
3) Ideally, we would fail if not all cores were seen as used. Unfortunately, |
|
|
|
this property (e.g. some cores reserved/unusable), then this condition |
|
|
|
this is only probabilistically true, and depends on the OS, it's |
|
|
|
will have to be rethought. |
|
|
|
scheduler, etc. So we just print out an indication of how many were seen; |
|
|
|
|
|
|
|
hopefully developers can use this to sanity check their system. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* Status shared across threads */ |
|
|
|
/* Status shared across threads */ |
|
|
@ -92,7 +93,6 @@ static void worker_thread(void *arg) { |
|
|
|
gpr_mu_unlock(&ct->mu); |
|
|
|
gpr_mu_unlock(&ct->mu); |
|
|
|
} |
|
|
|
} |
|
|
|
gpr_mu_lock(&ct->mu); |
|
|
|
gpr_mu_lock(&ct->mu); |
|
|
|
fprintf(stderr, "thread done on core %d\n", cpu); |
|
|
|
|
|
|
|
ct->r = r; /* make it look like we care about r's value... */ |
|
|
|
ct->r = r; /* make it look like we care about r's value... */ |
|
|
|
ct->nthreads--; |
|
|
|
ct->nthreads--; |
|
|
|
if (ct->nthreads == 0) { |
|
|
|
if (ct->nthreads == 0) { |
|
|
@ -104,11 +104,11 @@ static void worker_thread(void *arg) { |
|
|
|
|
|
|
|
|
|
|
|
static void cpu_test(void) { |
|
|
|
static void cpu_test(void) { |
|
|
|
gpr_uint32 i; |
|
|
|
gpr_uint32 i; |
|
|
|
|
|
|
|
int cores_seen = 0; |
|
|
|
struct cpu_test ct; |
|
|
|
struct cpu_test ct; |
|
|
|
gpr_thd_id thd; |
|
|
|
gpr_thd_id thd; |
|
|
|
ct.ncores = gpr_cpu_num_cores(); |
|
|
|
ct.ncores = gpr_cpu_num_cores(); |
|
|
|
GPR_ASSERT(ct.ncores > 0); |
|
|
|
GPR_ASSERT(ct.ncores > 0); |
|
|
|
fprintf(stderr, "#cores = %d\n", ct.ncores); |
|
|
|
|
|
|
|
ct.nthreads = (int)ct.ncores * 3; |
|
|
|
ct.nthreads = (int)ct.ncores * 3; |
|
|
|
ct.used = gpr_malloc(ct.ncores * sizeof(int)); |
|
|
|
ct.used = gpr_malloc(ct.ncores * sizeof(int)); |
|
|
|
memset(ct.used, 0, ct.ncores * sizeof(int)); |
|
|
|
memset(ct.used, 0, ct.ncores * sizeof(int)); |
|
|
@ -124,8 +124,11 @@ static void cpu_test(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
gpr_mu_unlock(&ct.mu); |
|
|
|
gpr_mu_unlock(&ct.mu); |
|
|
|
for (i = 0; i < ct.ncores; i++) { |
|
|
|
for (i = 0; i < ct.ncores; i++) { |
|
|
|
GPR_ASSERT(ct.used[i]); |
|
|
|
if (ct.used[i]) { |
|
|
|
|
|
|
|
cores_seen++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fprintf(stderr, "Saw %d/%d cores\n", cores_seen, ct.ncores); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
int main(int argc, char *argv[]) { |
|
|
|