mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Jackson <pj@sgi.com>
To: Marcel Zalmanovici <MARCEL@il.ibm.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Inconsistent timing results of multithreaded program on an SMP machine.
Date: Sun, 20 Nov 2005 06:02:12 -0800	[thread overview]
Message-ID: <20051120060212.16ff475c.pj@sgi.com> (raw)
In-Reply-To: <OFEF2B25AC.706FA8BA-ONC22570BF.00336502-C22570BF.0033F2B7@il.ibm.com>

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 <pj@sgi.com> 1.925.600.0401

  parent reply	other threads:[~2005-11-20 14:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-20  9:27 Marcel Zalmanovici
2005-11-20  9:54 ` Con Kolivas
2005-11-20 10:18   ` Marcel Zalmanovici
2005-11-20 10:28     ` Con Kolivas
2005-11-20 10:35       ` Muli Ben-Yehuda
2005-11-20 10:39         ` Con Kolivas
2005-11-20 10:43           ` Muli Ben-Yehuda
2005-11-20 10:50           ` Marcel Zalmanovici
2005-11-20 10:50             ` Con Kolivas
2005-11-20 10:43       ` Marcel Zalmanovici
2005-11-20 14:02 ` Paul Jackson [this message]
2005-11-24  9:50   ` Marcel Zalmanovici
     [not found] <OF507D27BA.6B51F19A-ONC22570C3.002E62D2-C22570C3.002F0C99@il.ibm.com>
2005-11-24  9:40 ` Con Kolivas
2005-11-24 10:00   ` Marcel Zalmanovici
2005-11-24 12:43     ` Paul Jackson
2005-12-04 15:26       ` Marcel Zalmanovici
2005-12-04 19:54         ` Paul Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051120060212.16ff475c.pj@sgi.com \
    --to=pj@sgi.com \
    --cc=MARCEL@il.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome