Re: how to know which cpu current process run

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi Valdis:
Thanks for your kind reply :)
2013/8/15  <Valdis.Kletnieks@xxxxxx>:
> On Thu, 15 Aug 2013 20:24:21 +0800, loody said:
>> is there any shell command or tool can let me know which cpu current
>> process run on?
>
> Why are you trying to check from the shell?  What problem are you
> trying to solve by knowing which CPU?
I adopt one sample code which uses sched_setaffinity to force user
program running on core#1, suppose my environment has core#0 and
core#1.

Theoretically, it is ONLY run on core#1.
When I use top, I cannot tell whether it runs on core#0 or core#1, so
I wrote this letter to ask help any tool checking what cpu this
program ran on.
i also attach my program for all your reference.

>And checking the *current* process tells you even less than "checking the
>process you care about" - because unless it's a shell builtin, when you
>launch the command, it will quite possibly end up on some core other than
>the one the shell is running on....

it seems I use wrong way to express what I need.
I need any tool to check whether the process I assigned to cpu with
sched_setaffinity  did work.

-- 
Regards,
/*
 * Example of sched_set_affinity and sched_get_affinity
 * 	Robert Love, 20020227
 */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sched.h>
#include <linux/unistd.h>
/*
 * provide the proper syscall information if our libc
 * is not yet updated.
 */
#ifndef __NR_sched_setaffinity
#define __NR_sched_setaffinity	241
#define __NR_sched_getaffinity	242
_syscall3 (int, sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr)
_syscall3 (int, sched_getaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr)
#endif

int main(int argc, char * argv[])
{
	unsigned long new_mask = 1;
	unsigned int len = sizeof(new_mask);
	unsigned long cur_mask;
	pid_t p = 0;
	int ret;

	while(1){	
		ret = sched_getaffinity(p, len, NULL);
		printf(" sched_getaffinity = %d, len = %u\n", ret, len);

		ret = sched_getaffinity(p, len, &cur_mask);
		printf(" sched_getaffinity = %d, cur_mask = %08lx\n", ret, cur_mask);

		ret = sched_setaffinity(p, len, &new_mask);
		printf(" sched_setaffinity = %d, new_mask = %08lx\n", ret, new_mask);

		ret = sched_getaffinity(p, len, &cur_mask);
		printf(" sched_getaffinity = %d, cur_mask = %08lx\n", ret, cur_mask);
		
		sleep (10);
	}
	return 0;
}
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux