From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cs3.bu.edu (cs3.bu.edu [128.197.12.8]) by ozlabs.org (Postfix) with ESMTP id 663D0DDE08 for ; Wed, 12 Sep 2007 11:10:24 +1000 (EST) From: "Ilya Lipovsky" To: "'Nguyen Nguyen'" Subject: RE: futex priority based wakeup Date: Tue, 11 Sep 2007 21:09:51 -0400 Message-ID: <000701c7f4d9$b124fba0$3a0d10ac@Radstone.Local> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0008_01C7F4B8.2A135BA0" In-Reply-To: <1656e050709111714g1a84656bvd7823f5fc43345dd@mail.gmail.com> Cc: "'Benedict, Michael'" , linuxppc-embedded@ozlabs.org List-Id: Linux on Embedded PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C7F4B8.2A135BA0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Good info. Indeed, looks like this is what glibc actually does: http://www.cygwin.com/ml/libc-alpha/2007-06/msg00097.html _____ From: tinghich@gmail.com [mailto:tinghich@gmail.com] On Behalf Of Nguyen Nguyen Sent: Tuesday, September 11, 2007 8:15 PM To: Ilya Lipovsky Cc: Benedict, Michael; linuxppc-embedded@ozlabs.org Subject: Re: futex priority based wakeup I have seen something similar before. Our fix was to use pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) so child threads wouldn't inherit attribute from parent. Hope it helps. On 9/11/07, Ilya Lipovsky wrote: Hmm. Just for kicks - inside the important thread could you add: int curpolicy; struct sched_param sp; pthread_getschedparam (pthread_self (), &curpolicy, &sp) printf("important's policy is %d and priority is %d\n", curpolicy, sp.__sched_priority); before the very first futex syscall and after your "printf("important got futex!\n");" line. Do similar for the unimportant thread, and see if you get anything weird - e.g. priorities come out to be the same for threads. -----Original Message----- From: linuxppc-embedded-bounces+lipovsky=cs.bu.edu@ozlabs.org [mailto: linuxppc-embedded-bounces+lipovsky=cs.bu.edu@ozlabs.org] On Behalf Of Benedict, Michael Sent: Monday, September 10, 2007 5:41 PM To: linuxppc-embedded@ozlabs.org Subject: RE: futex priority based wakeup Ilya Lipovsky wrote: > Your code looks correct to me, so if the kernel developers > did their job > correctly, the only potentially weak link is glibc. > Well, either the kernel developers didn't do their job, or I am missing something. The following also fails, and it should be bypassing glibc: #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include int myfutex = 0; void *important(void *ign) { sleep(1); printf("important waiting for futex\n"); fflush(stdout); if(syscall(SYS_futex, &myfutex, FUTEX_WAIT, 0, NULL)) { perror("futex"); exit(1); } else { printf("important got futex!\n"); fflush(stdout); syscall(SYS_futex, &myfutex, FUTEX_WAKE, 1, NULL); } return NULL; } void *unimportant(void *ign) { printf("unimportant waiting for futex\n"); fflush(stdout); if(syscall(SYS_futex, &myfutex, FUTEX_WAIT, 0, NULL)) { perror("futex"); exit(1); } else { printf("unimportant got futex!\n"); fflush(stdout); syscall(SYS_futex, &myfutex, FUTEX_WAKE, 1, NULL); } return NULL; } int main() { struct sched_param p; pthread_attr_t attr; pthread_t i, u; p.__sched_priority = sched_get_priority_min(SCHED_FIFO); if(-1 == p.__sched_priority) { perror("sched_get_priority_min"); return 1; } pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_attr_setschedparam(&attr, &p); pthread_create(&u, &attr, unimportant, NULL); p.__sched_priority = sched_get_priority_max(SCHED_FIFO); pthread_attr_setschedparam(&attr, &p); pthread_create(&i, &attr, important, NULL); sleep(5); printf("futex FUTEX_WAKE\n"); fflush(stdout); syscall(SYS_futex, &myfutex, FUTEX_WAKE, 1, NULL); pthread_join(u, NULL); pthread_join(i, NULL); return 0; } Which produces: unimportant waiting for futex important waiting for futex futex FUTEX_WAKE unimportant got futex! important got futex! Could someone with 2.6.22 please verify? _______________________________________________ Linuxppc-embedded mailing list Linuxppc-embedded@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-embedded _______________________________________________ Linuxppc-embedded mailing list Linuxppc-embedded@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-embedded ------=_NextPart_000_0008_01C7F4B8.2A135BA0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Good info. Indeed, looks like this = is what glibc actually does:

 

http:/= /www.cygwin.com/ml/libc-alpha/2007-06/msg00097.html=

 

 

 


From: tinghich@gmail.com [mailto:tinghich@gmail.com] On Behalf Of Nguyen Nguyen
Sent: Tuesday, September = 11, 2007 8:15 PM
To: Ilya Lipovsky
Cc: Benedict, Michael; linuxppc-embedded@ozlabs.org
Subject: Re: futex = priority based wakeup

 

I have seen = something similar before.  Our fix was to use pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) so child threads wouldn't inherit attribute from parent.  Hope it helps.

On 9/11/07, Ilya Lipovsky <lipovsky@cs.bu.edu> wrote:

Hmm. Just for = kicks - inside the important thread could you add:

int curpolicy;
struct sched_param sp;
pthread_getschedparam (pthread_self (), &curpolicy, &sp)
printf("important's policy is %d and priority is %d\n", = curpolicy,
sp.__sched_priority);

before the very first futex syscall and after your = "printf("important got
futex!\n");" line.

Do similar for the unimportant thread, and see if you get anything weird = -
e.g. priorities come out to be the same for threads.


-----Original Message-----
From: linuxppc-embedded-bounces+lipovsky=3Dcs.bu.edu@ozlabs.org
[mailto: linuxppc-embedded-bounces+lipovsky=3Dcs.bu.edu@ozlabs.org] On = Behalf
Of Benedict, Michael
Sent: Monday, September 10, 2007 5:41 PM
To: linuxppc-embedded@ozlabs.org=
Subject: RE: futex priority based wakeup

Ilya Lipovsky wrote:
> Your code looks correct to me, so if the kernel developers
> did their job
> correctly, the only potentially weak link is glibc.
>

Well, either the kernel developers didn't do their job, or I am = missing
something.  The following also fails, and it should be = bypassing glibc:

#define _XOPEN_SOURCE 600

#include <linux/futex.h>
#include <sys/time.h>
#include <asm/atomic.h>

#include <sys/syscall.h>
#include <unistd.h>

#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

int myfutex =3D 0;

void *important(void *ign)
{
        sleep(1);
        printf("important = waiting for futex\n");
        fflush(stdout);
        if(syscall(SYS_futex, &myfutex, FUTEX_WAIT, 0, NULL)) {
            &= nbsp;   perror("futex");
            &= nbsp;   exit(1);
        } else {
            &= nbsp;   printf("important got futex!\n");
            &= nbsp;   fflush(stdout);
            &= nbsp;   syscall(SYS_futex, &myfutex, FUTEX_WAKE, 1, NULL);
}

        return NULL;
}


void *unimportant(void *ign)
{
        printf("unimportant = waiting for futex\n");
        fflush(stdout);
        if(syscall(SYS_futex, &myfutex, FUTEX_WAIT, 0, NULL)) {
            &= nbsp;   perror("futex");
            &= nbsp;   exit(1);
        } else {
            &= nbsp;   printf("unimportant got futex!\n");
            &= nbsp;   fflush(stdout);
            &= nbsp;   syscall(SYS_futex, &myfutex, FUTEX_WAKE, 1, NULL);
}

        return NULL;
}

int main()
{
        struct sched_param = p;
        pthread_attr_t attr;
        pthread_t i, u;

        p.__sched_priority =3D sched_get_priority_min(SCHED_FIFO);
        if(-1 =3D=3D = p.__sched_priority) {
            &= nbsp;   perror("sched_get_priority_min");
            &= nbsp;   return 1;
        }
        pthread_attr_init(&at= tr);
        pthread_attr_setschedpoli= cy(&attr, SCHED_FIFO);
        pthread_attr_setschedpara= m(&attr, &p);
        pthread_create(&u, &attr, unimportant, NULL);

        p.__sched_priority =3D sched_get_priority_max(SCHED_FIFO);
        pthread_attr_setschedpara= m(&attr, &p);
        pthread_create(&i, &attr, important, NULL);

        sleep(5);
        printf("futex FUTEX_WAKE\n");
        fflush(stdout);
        syscall(SYS_futex, &myfutex, FUTEX_WAKE, 1, NULL);

        pthread_join(u, = NULL);
        pthread_join(i, = NULL);

        return 0;
}

Which produces:
unimportant waiting for futex
important waiting for futex
futex FUTEX_WAKE
unimportant got futex!
important got futex!


Could someone with 2.6.22 please verify?

_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org=
https://oz= labs.org/mailman/listinfo/linuxppc-embedded

_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org=
https://oz= labs.org/mailman/listinfo/linuxppc-embedded
<= /p>

 

------=_NextPart_000_0008_01C7F4B8.2A135BA0--