public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Schmidt <mista.tapas@gmx.net>
To: Ingo Molnar <mingo@elte.hu>
Cc: Paul Davis <paul@linuxaudiosystems.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Lee Revell <rlrevell@joe-job.com>,
	mark_h_johnson@raytheon.com, Bill Huey <bhuey@lnxw.com>,
	Adam Heath <doogie@debian.org>,
	Michal Schmidt <xschmi00@stud.feec.vutbr.cz>,
	Fernando Pablo Lopez-Lezcano <nando@ccrma.stanford.edu>,
	Karsten Wiese <annabellesgarden@yahoo.de>,
	jackit-devel <jackit-devel@lists.sourceforge.net>,
	Rui Nuno Capela <rncbc@rncbc.org>
Subject: Re: [Fwd: Re: [patch] Real-Time Preemption, -RT-2.6.9-mm1-V0.4]
Date: Sat, 30 Oct 2004 19:53:15 +0200	[thread overview]
Message-ID: <20041030195315.37bed27f@mango.fruits.de> (raw)
In-Reply-To: <20041030131507.GA5189@elte.hu>

[-- Attachment #1: Type: text/plain, Size: 2811 bytes --]

On Sat, 30 Oct 2004 15:15:07 +0200
Ingo Molnar <mingo@elte.hu> wrote:

> should have mentioned that in the user-triggered modus you have to do
> the latency measurement in userspace. It is only the trace that is
> correct, for the time being. This trace shows what i'd expect a jackd
> wakeup to look like normally: 13 usecs.
> 
> 	Ingo
> 

Hi,

i thought, why not try to get jack out of the equation first and use a
different irq source. So i wrote a small test app for /dev/rtc to see if i
see the same erratic behaviour [.cc source file atached. find a small
tarball here: http://affenbande.org/~tapas/wakeup.tgz (it has a simple
makefile, plus a script which does the chrt thing to make it SCHED_FIFO)].

This program takes two parameters: the desired freq of the rtc and the
number of irq's to be measured.

Then it polls on the fd of /dev/rtc and takes a cpu cycle count timestamp as
soon as poll returns. At the end of the program i tried to gather some
[useful ???] statistics of the data: 

- the mean difference in cycles between two wakeups

- the max difference in cycles between two wakeups (and how much this
differs from the  mean difference)

- the min difference in cycles between two wakeups (and how much this
differs from the  mean difference)

- the mean difference from the mean difference :)

And alas, wiggling windows screws up the timing on V0.5.6 for this, too.

dunno, if this is any useful to you, but i felt the urge to try it :)

	flo


P.S.: don't forget to make your rtc irq SCHED_FIFO with a high priority, too

here's a sample output with window wiggling in X (rt_wakeup runs chrt -f 90
wakeup, so make rtc at least prio 91):

~/source/my_projects/wakeup$ ./rt_wakeup 1024 6000
freq: 1024 #: 6000
setting up /dev/rtc...
locking memory...
turning irq on, beginning measurement (might take a while)...
...measurement done

mean cycle difference betweem two wakeups: 1.17845e+06 cycles

min. cycle difference betweem two wakeups: 185992 cycles (#: 1563) 
 diff from mean diff: 992461

max. cycle difference betweem two wakeups: 9.73166e+06 cycles (#: 1546) 
 diff from mean diff: 8.5532e+06
                      ^this is bad i suppose :)

mean difference from mean difference: 25279.2 cycles


here's one on a rather idle system:

~/source/my_projects/wakeup$ ./rt_wakeup 1024 6000
freq: 1024 #: 6000
setting up /dev/rtc...
locking memory...
turning irq on, beginning measurement (might take a while)...
...measurement done

mean cycle difference betweem two wakeups: 1.16697e+06 cycles

min. cycle difference betweem two wakeups: 1.1486e+06 cycles (#: 5492) 
 diff from mean diff: 18379.2

max. cycle difference betweem two wakeups: 1.18439e+06 cycles (#: 5491) 
 diff from mean diff: 17417.8

mean difference from mean difference: 1144.82 cycles
~/source/my_projects/wakeup$ 

[-- Attachment #2: wakeup.cc --]
[-- Type: text/x-c++src, Size: 4266 bytes --]

#include <iostream>
#include <sstream>
#include <string>

#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <poll.h>

#include <cmath>

// this program is partly ripped off the rtc docs in the linux kernel source tree

// the cycle count count ripped from jackd
typedef unsigned long long cycles_t;

extern cycles_t cacheflush_time;

#define rdtscll(val) \
     __asm__ __volatile__("rdtsc" : "=A" (val))

static inline cycles_t get_cycles (void)
{
	unsigned long long ret;

	rdtscll(ret);
	return ret;
}



int main(int argc, char *argv[]) {
  if (argc < 3) {
    std::cout << "usage: wakeup [freqency(hz)] [number of interrupts]" << std::endl;
  }
  
  std::stringstream args;
  args << argv[1] << " " << argv[2];
  
  int freq;
  args >> freq;

  int number;
  args >> number;

  std::cout << "freq: " << freq << " #: " << number << std::endl;

  if (number < 3) {
    std::cout << "number of irq's must be >= 3" << std::endl;
    return(0);
  }

  // an array to store the cycles for each interrupt in.
  cycles_t *cycles = new cycles_t[number];

  std::cout << "setting up /dev/rtc..." << std::endl;

  int fd;
  fd = open("/dev/rtc", O_RDONLY);
  if (fd ==  -1) {
    perror("/dev/rtc");
    exit(errno);
  }
  
  int retval = ioctl(fd, RTC_IRQP_SET, freq);
  if (retval == -1) {
    perror("ioctl");
    exit(errno);
  }

  
  // we poll only on a single descriptor, the /dev/rtc one
  struct pollfd fds[1];
  pollfd pfd;
  pfd.fd = fd;
  pfd.events = POLLRDNORM|POLLRDBAND;
  fds[0] = pfd;


  // we set the timeout to 8 periods
  int timeout;
  timeout = 8*( (int)( (1.0f/(float)freq)*1000.0f ) );

  std::cout << "locking memory..." << std::endl;
  mlockall(MCL_CURRENT);
  // std::cout << "sleeping 1 sec" << std::endl;
  // sleep(1);

  std::cout << "turning irq on, beginning measurement (might take a while)..." << std::endl;
  
  retval = ioctl(fd, RTC_PIE_ON, 0);
  if (retval == -1) {
    perror("ioctl");
    exit(errno);
  }
  
  unsigned long data;
  for (int i = 0; i < number; ++i) {
    // first we poll, until data is available
    retval = poll(fds, 1, timeout);
    if (retval == -1) {
      perror("poll");
      exit(errno);
    }

    // then we take a timestamp;
    cycles[i] = get_cycles();
    // std::cout << "irq!" << std::endl;
    
    // then we read it
    retval = read(fd, &data, sizeof(unsigned long));
    if (retval == -1) {
      perror("read");
      exit(errno);
    }

    // see if the high bytes of the data contains a number of irq > 1. probably wrong,
    data = (data >> 16);
    if (data > 1) {std::cout << "more than 1 irq happened inbetween this and last wakeup" << std::endl;}
  }

  
  std::cout << "...measurement done" << std::endl;

  // first one is often skewed
  double mean_diff = ((double)cycles[number-1] - (double)cycles[1])/(double)(number-2);

  // std::cout << "0: \t" << cycles[0] << std::endl;
  double min_diff, max_diff;
  min_diff = max_diff = (double)(cycles[2] - cycles[1]);

  unsigned int min_diff_i, max_diff_i;
  min_diff_i = max_diff_i = 2;
  
  double mean_diff_diff = 0;

  for (int i = 2; i < number; ++i) {
    double diff = (double)(cycles[i] - cycles[i-1]);
    if (diff < min_diff) {min_diff = diff; min_diff_i = i;}
    if (diff > max_diff) {max_diff = diff; max_diff_i = i;}

    mean_diff_diff += fabs(mean_diff - diff);
    // std::cout << i << ": \t" << cycles[i] << std::endl;
  }
  mean_diff_diff /= (double)(number - 2);
  
  std::cout << std::endl << "mean cycle difference betweem two wakeups: " 
	    << mean_diff 
	    << " cycles" <<  std::endl << std::endl;

  std::cout << "min. cycle difference betweem two wakeups: " 
	    << min_diff << " cycles (#: " << min_diff_i << ") \n diff from mean diff: " 
	    << fabs(min_diff - mean_diff) << std::endl << std::endl;

  std::cout << "max. cycle difference betweem two wakeups: " 
	    << max_diff << " cycles (#: " << max_diff_i << ") \n diff from mean diff: " 
	    << fabs(max_diff - mean_diff) << std::endl << std::endl;
  
  std::cout << "mean difference from mean difference: " 
	    << mean_diff_diff << " cycles" << std::endl;
  
  // return success
  close(fd);
  return 1;
}

  reply	other threads:[~2004-10-30 17:36 UTC|newest]

Thread overview: 152+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1099008264.4199.4.camel@krustophenia.net>
2004-10-29  0:57 ` [Fwd: Re: [patch] Real-Time Preemption, -RT-2.6.9-mm1-V0.4] Paul Davis
2004-10-29  2:10   ` Lee Revell
2004-10-29  8:02   ` Ingo Molnar
2004-10-29  8:21     ` Thomas Gleixner
2004-10-29  9:09       ` Ingo Molnar
2004-10-29 11:01         ` Paul Davis
2004-10-29 11:14           ` Ingo Molnar
2004-10-29 11:26             ` Paul Davis
2004-10-29 11:36               ` Ingo Molnar
2004-10-29 13:35                 ` Paul Davis
2004-10-29 13:55                   ` Ingo Molnar
2004-10-29 14:03                     ` Paul Davis
2004-10-29 14:15                       ` Ingo Molnar
2004-10-29 16:14             ` Ingo Molnar
2004-10-29 16:21               ` Ingo Molnar
2004-10-29 16:32               ` Florian Schmidt
2004-10-29 16:23                 ` Ingo Molnar
2004-10-29 16:31                   ` Ingo Molnar
2004-10-29 16:37                     ` Ingo Molnar
2004-10-29 16:53                       ` Ingo Molnar
2004-10-29 17:16                     ` Florian Schmidt
2004-10-29 17:02                       ` Ingo Molnar
2004-10-29 17:09                         ` Ingo Molnar
2004-10-29 17:16                           ` Ingo Molnar
2004-10-29 17:33                           ` Florian Schmidt
2004-10-29 17:21                             ` Ingo Molnar
2004-10-29 17:22                               ` Ingo Molnar
2004-10-29 18:36                                 ` Florian Schmidt
2004-10-29 20:33                                   ` Ingo Molnar
2004-10-29 20:51                                     ` Paul Davis
2004-10-29 21:11                                       ` Ingo Molnar
2004-10-30  1:06                                         ` Paul Davis
2004-10-30 11:34                                           ` Ingo Molnar
2004-11-26 17:16                                         ` [Jackit-devel] " Jack O'Quin
2004-10-29 20:42                                   ` Ingo Molnar
2004-10-29 21:31                                     ` Florian Schmidt
2004-10-29 21:25                                       ` Ingo Molnar
2004-10-29 21:42                                         ` Lee Revell
2004-10-29 21:46                                           ` Ingo Molnar
2004-10-29 21:53                                             ` Lee Revell
2004-10-29 23:12                                             ` Lee Revell
2004-10-30 11:58                                               ` Ingo Molnar
2004-10-30 17:49                                                 ` Lee Revell
2004-10-30 19:17                                                   ` Ingo Molnar
2004-10-30 19:43                                                     ` Lee Revell
2004-10-30 19:47                                                     ` Florian Schmidt
2004-10-30 19:37                                                       ` Ingo Molnar
2004-10-30 19:57                                                         ` Florian Schmidt
2004-10-30 19:52                                                       ` Lee Revell
2004-10-30 20:15                                                         ` Florian Schmidt
2004-10-30 20:26                                                           ` Lee Revell
2004-10-30 21:13                                                             ` Florian Schmidt
2004-10-30 21:26                                                               ` Lee Revell
2004-10-30 21:38                                                                 ` Florian Schmidt
2004-10-30 23:12                                                                   ` Lee Revell
2004-10-31 12:07                                                                   ` Ingo Molnar
2004-10-31 12:48                                                                     ` Ingo Molnar
2004-10-31 12:54                                                                       ` Lee Revell
2004-10-31 13:13                                                                         ` Ingo Molnar
2004-10-31 13:40                                                                           ` Ingo Molnar
2004-10-31 15:20                                                                             ` Florian Schmidt
2004-10-31 15:59                                                                               ` Florian Schmidt
2004-10-31 19:06                                                                                 ` Florian Schmidt
2004-11-01 13:42                                                                                   ` Ingo Molnar
2004-11-01 13:53                                                                                     ` Ingo Molnar
2004-11-01 14:06                                                                                       ` Ingo Molnar
2004-11-01 15:47                                                                                         ` Thomas Gleixner
2004-11-01 17:55                                                                                           ` Lee Revell
2004-11-01 17:58                                                                                             ` Thomas Gleixner
2004-11-01 18:43                                                                                             ` Ingo Molnar
2004-11-01 18:46                                                                                           ` Ingo Molnar
2004-11-01 22:30                                                                                             ` Florian Schmidt
2004-11-01 22:40                                                                                               ` Bill Huey
2004-11-01 22:51                                                                                                 ` Florian Schmidt
2004-11-01 22:59                                                                                                   ` Bill Huey
2004-11-02  8:02                                                                                                     ` Ingo Molnar
2004-11-02  8:07                                                                                               ` Ingo Molnar
2004-11-02 15:06                                                                                           ` [patch] Real-Time Preemption, -RT-2.6.9-mm1-V0.6.8 Ingo Molnar
2004-11-02 17:52                                                                                             ` K.R. Foley
2004-11-02 19:37                                                                                               ` Ingo Molnar
2004-11-02 19:40                                                                                                 ` K.R. Foley
2004-11-02 19:24                                                                                             ` Norberto Bensa
2004-11-02 19:35                                                                                               ` Ingo Molnar
2004-11-02 23:09                                                                                             ` Karsten Wiese
2004-11-03  1:12                                                                                               ` Ingo Molnar
2004-11-03 10:15                                                                                                 ` Karsten Wiese
2004-11-01 17:04                                                                                         ` [Fwd: Re: [patch] Real-Time Preemption, -RT-2.6.9-mm1-V0.4] Rui Nuno Capela
2004-11-01 17:08                                                                                           ` Thomas Gleixner
2004-11-01 20:00                                                                                             ` Rui Nuno Capela
2004-11-01 17:24                                                                                         ` K.R. Foley
2004-11-02  0:22                                                                                         ` Michal Schmidt
2004-11-01 13:54                                                                                     ` Paul Davis
2004-11-01 14:30                                                                                       ` Ingo Molnar
2004-11-01 19:30                                                                                         ` Paul Davis
2004-11-02  8:17                                                                                           ` Ingo Molnar
2004-11-01 14:03                                                                                     ` Florian Schmidt
2004-11-01 14:12                                                                                       ` Ingo Molnar
2004-11-01 15:29                                                                                       ` K.R. Foley
2004-11-02 23:41                                                                                     ` [Fwd: Re: [patch] Real-Time Preemption, -RT-2.6.9-mm1-V0.6] Remi Colinet
2004-11-03  1:04                                                                                       ` Remi Colinet
2004-11-01 11:55                                                                                 ` [Fwd: Re: [patch] Real-Time Preemption, -RT-2.6.9-mm1-V0.4] Ingo Molnar
2004-11-01 12:37                                                                                   ` Ingo Molnar
2004-11-01 12:35                                                                                     ` Thomas Gleixner
2004-11-01 12:51                                                                                       ` Ingo Molnar
2004-11-01 13:15                                                                                         ` Ingo Molnar
2004-11-01 13:40                                                                                           ` Florian Schmidt
2004-11-01 13:48                                                                                             ` Ingo Molnar
2004-11-01 16:47                                                                                   ` Rui Nuno Capela
2004-10-31 23:16                                                                             ` Michal Schmidt
2004-11-01  0:05                                                                             ` Magnus Määttä
2004-10-31 13:11                                                                       ` Ingo Molnar
2004-10-31 14:11                                                                       ` Florian Schmidt
2004-10-31 13:22                                                                         ` Ingo Molnar
2004-10-31 14:28                                                                           ` Florian Schmidt
2004-10-31 13:30                                                                         ` Ingo Molnar
2004-10-31 21:58                                                                     ` Rui Nuno Capela
2004-10-31 22:11                                                                     ` K.R. Foley
2004-10-31  2:20                                                               ` Lee Revell
2004-10-31 10:00                                                                 ` Florian Schmidt
2004-10-31 12:09                                                                   ` Lee Revell
2004-10-31 12:19                                                                     ` Ingo Molnar
2004-10-31 12:35                                                                       ` Lee Revell
2004-10-31 12:39                                                                         ` Ingo Molnar
2004-10-30 20:05                                                       ` Lee Revell
2004-10-30 20:29                                                         ` Florian Schmidt
2004-10-30  0:15                                             ` Lee Revell
2004-10-29 22:31                                         ` Florian Schmidt
2004-10-29 22:50                                           ` Florian Schmidt
2004-10-30 13:15                                             ` Ingo Molnar
2004-10-30 17:53                                               ` Florian Schmidt [this message]
2004-10-30  3:36                                           ` Lee Revell
2004-10-30  3:48                                             ` Lee Revell
2004-10-30 11:16                                               ` Ingo Molnar
2004-10-30 17:44                                                 ` Lee Revell
2004-10-30 11:28                                             ` Ingo Molnar
2004-10-30 11:33                                               ` Ingo Molnar
2004-10-30 13:16                                               ` Florian Schmidt
2004-10-30  1:10                                         ` Lee Revell
2004-10-30  1:15                                         ` Lee Revell
2004-10-29  8:59     ` Ingo Molnar
2004-10-29  9:29       ` Ingo Molnar
2004-10-29 13:48     ` Ingo Molnar
2004-10-29 14:19       ` Paul Davis
2004-10-29 14:27         ` Ingo Molnar
2004-10-29 14:31         ` Ingo Molnar
2004-10-29 14:38           ` Paul Davis
2004-10-29 19:33     ` Lee Revell
2004-10-29 19:35       ` Thomas Gleixner
2004-11-01 14:32 Mark_H_Johnson
2004-11-01 14:36 ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2004-11-01 16:34 Mark_H_Johnson
2004-11-01 18:48 ` Ingo Molnar

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=20041030195315.37bed27f@mango.fruits.de \
    --to=mista.tapas@gmx.net \
    --cc=annabellesgarden@yahoo.de \
    --cc=bhuey@lnxw.com \
    --cc=doogie@debian.org \
    --cc=jackit-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark_h_johnson@raytheon.com \
    --cc=mingo@elte.hu \
    --cc=nando@ccrma.stanford.edu \
    --cc=paul@linuxaudiosystems.com \
    --cc=rlrevell@joe-job.com \
    --cc=rncbc@rncbc.org \
    --cc=tglx@linutronix.de \
    --cc=xschmi00@stud.feec.vutbr.cz \
    /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