[lkml]   [2002]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Futexes V :
On Wed, 6 Mar 2002 15:36:25 -0500
Hubertus Franke <> wrote:

> On Wednesday 06 March 2002 11:13 am, Hubertus Franke wrote:
> I cut a new version with what I was previously discussing.
> Now we have two kind of wakeup mechanism
> (a) regular wakeup (as was) which basically gives you convoy avoidance
> (b) fair wakeup (will first wake a waiting process up .. FIFO)
> Basically integrated 2 prior patches of Rusty

I like your numbers. Since I think fairness is nice, but lack of starvation
is vital, I've been trying to starve a process.

So far, I've not managed it. Please hack on the below code, and see if
you can manage it. If not, I think we can say "not a problem in real life",
and just stick with the fastest implementation.


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <signal.h>
#include "usersem.h"

#ifndef PROT_SEM
#define PROT_SEM 0x8

static void spinner(struct futex *sem, int hold)
while (1) {
if (hold) sleep(1);

/* Test maximum time to lock given furious spinners. */
int main(int argc, char *argv[])
struct futex *sem;
unsigned int i;
unsigned long maxtime = 0;
pid_t children[100];

if (argc != 3) {
fprintf(stderr, "Usage: starve <numspinners> <iterations>\n");

sem = malloc(sizeof(*sem));
futex_region(sem, sizeof(*sem));
for (i = 0; i < atoi(argv[1]); i++) {
children[i] = fork();
if (children[i] == 0)
spinner(sem, i < atoi(argv[1])/2);

for (i = 0; i < atoi(argv[2]); i++) {
struct timeval start, end, diff;

gettimeofday(&start, NULL);
gettimeofday(&end, NULL);
timersub(&end, &start, &diff);
printf("Wait time: %lu.%06lu\n", diff.tv_sec, diff.tv_usec);
if (diff.tv_sec * 1000000 + diff.tv_usec > maxtime)
maxtime = diff.tv_sec * 1000000 + diff.tv_usec;

/* Kill children */
for (i = 0; i < atoi(argv[1]); i++)
kill(children[i], SIGTERM);

printf("Worst case: %lu\n", maxtime);

Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:21    [W:0.087 / U:8.500 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site