Marcel wrote:
> Instead what I've got was an oscillation where the maximum time was twice
> and more than the minimum!! For a short test results ranged ~7sec to ~16 ...
Just for grins, try displaying which cpu each thread runs on. Display the
return from "latestcpu(getpid())" in the two per-thread printf's, to display
the thread's cpu at the beginning and end of each compute_thread(). Perhaps
you will notice that the per-thread cpu correlates with the test times.
/*
* int latestcpu(pid_t pid)
*
* Copyright (C) 2005 Silicon Graphics, Inc.
* This code is subject to the terms and conditions of the
* GNU General Public License.
*
* Return most recent CPU on which task pid executed.
*
* The last used CPU is visible for a given pid as field #39
* (starting with #1) in the file /proc/<pid>/stat. Currently
* this file has 41 fields, in which case this is the 3rd to
* the last field.
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <limits.h>
#include <linux/limits.h>
int latestcpu(pid_t pid)
{
char buf[PATH_MAX];
int fd;
int cpu = -1;
snprintf(buf, sizeof(buf), "/proc/%d/stat", pid);
fd = open(buf, O_RDONLY);
buf[0] = 0; /* in case fd < 0 and read() is no-op */
read(fd, buf, sizeof(buf));
close(fd);
sscanf(buf, "%*u %*s %*s %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u %u", /* 39th field */
&cpu);
return cpu;
}
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]