@@ -3565,6 +3565,59 @@ int get_physical_node_id(struct cpu_topology *thiscpu)
3565
3565
return -1 ;
3566
3566
}
3567
3567
3568
+ static int parse_cpu_str (char * cpu_str , cpu_set_t * cpu_set , int cpu_set_size )
3569
+ {
3570
+ unsigned int start , end ;
3571
+ char * next = cpu_str ;
3572
+
3573
+ while (next && * next ) {
3574
+
3575
+ if (* next == '-' ) /* no negative cpu numbers */
3576
+ return 1 ;
3577
+
3578
+ start = strtoul (next , & next , 10 );
3579
+
3580
+ if (start >= CPU_SUBSET_MAXCPUS )
3581
+ return 1 ;
3582
+ CPU_SET_S (start , cpu_set_size , cpu_set );
3583
+
3584
+ if (* next == '\0' || * next == '\n' )
3585
+ break ;
3586
+
3587
+ if (* next == ',' ) {
3588
+ next += 1 ;
3589
+ continue ;
3590
+ }
3591
+
3592
+ if (* next == '-' ) {
3593
+ next += 1 ; /* start range */
3594
+ } else if (* next == '.' ) {
3595
+ next += 1 ;
3596
+ if (* next == '.' )
3597
+ next += 1 ; /* start range */
3598
+ else
3599
+ return 1 ;
3600
+ }
3601
+
3602
+ end = strtoul (next , & next , 10 );
3603
+ if (end <= start )
3604
+ return 1 ;
3605
+
3606
+ while (++ start <= end ) {
3607
+ if (start >= CPU_SUBSET_MAXCPUS )
3608
+ return 1 ;
3609
+ CPU_SET_S (start , cpu_set_size , cpu_set );
3610
+ }
3611
+
3612
+ if (* next == ',' )
3613
+ next += 1 ;
3614
+ else if (* next != '\0' && * next != '\n' )
3615
+ return 1 ;
3616
+ }
3617
+
3618
+ return 0 ;
3619
+ }
3620
+
3568
3621
int get_thread_siblings (struct cpu_topology * thiscpu )
3569
3622
{
3570
3623
char path [80 ], character ;
@@ -6384,9 +6437,6 @@ void probe_sysfs(void)
6384
6437
*/
6385
6438
void parse_cpu_command (char * optarg )
6386
6439
{
6387
- unsigned int start , end ;
6388
- char * next ;
6389
-
6390
6440
if (!strcmp (optarg , "core" )) {
6391
6441
if (cpu_subset )
6392
6442
goto error ;
@@ -6409,52 +6459,8 @@ void parse_cpu_command(char *optarg)
6409
6459
6410
6460
CPU_ZERO_S (cpu_subset_size , cpu_subset );
6411
6461
6412
- next = optarg ;
6413
-
6414
- while (next && * next ) {
6415
-
6416
- if (* next == '-' ) /* no negative cpu numbers */
6417
- goto error ;
6418
-
6419
- start = strtoul (next , & next , 10 );
6420
-
6421
- if (start >= CPU_SUBSET_MAXCPUS )
6422
- goto error ;
6423
- CPU_SET_S (start , cpu_subset_size , cpu_subset );
6424
-
6425
- if (* next == '\0' )
6426
- break ;
6427
-
6428
- if (* next == ',' ) {
6429
- next += 1 ;
6430
- continue ;
6431
- }
6432
-
6433
- if (* next == '-' ) {
6434
- next += 1 ; /* start range */
6435
- } else if (* next == '.' ) {
6436
- next += 1 ;
6437
- if (* next == '.' )
6438
- next += 1 ; /* start range */
6439
- else
6440
- goto error ;
6441
- }
6442
-
6443
- end = strtoul (next , & next , 10 );
6444
- if (end <= start )
6445
- goto error ;
6446
-
6447
- while (++ start <= end ) {
6448
- if (start >= CPU_SUBSET_MAXCPUS )
6449
- goto error ;
6450
- CPU_SET_S (start , cpu_subset_size , cpu_subset );
6451
- }
6452
-
6453
- if (* next == ',' )
6454
- next += 1 ;
6455
- else if (* next != '\0' )
6456
- goto error ;
6457
- }
6462
+ if (parse_cpu_str (optarg , cpu_subset , cpu_subset_size ))
6463
+ goto error ;
6458
6464
6459
6465
return ;
6460
6466
0 commit comments