Hi Gilles,

On Tue, 2008-10-14 at 14:39 +0200, Gilles Carry wrote:
> From: gilles.carry <[EMAIL PROTECTED]>
> 
> Syscall sched_setaffinity fails if choosen cpu is not online.
> In set_affinity, thread_id value is used as cpuid when calling
> sched_setaffinity. This fails when disabling cpus because threads ids
> and online cpu ids don't necessarly match.
> 
> This patch simply increments cpuid (max. 8192) until it finds an online cpu.
> This guaranties that no more than one thread is assigned to one cpu.
> If set_affinity is called more times than there are online cpus
> then matrix_mult.c fails.

This appears to make things a little more robust.  A couple nits.

> ---
>  testcases/realtime/func/matrix_mult/matrix_mult.c |   30 
> ++++++++++++++-------
>  1 files changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/testcases/realtime/func/matrix_mult/matrix_mult.c 
> b/testcases/realtime/func/matrix_mult/matrix_mult.c
> index 21fded8..55c1086 100644
> --- a/testcases/realtime/func/matrix_mult/matrix_mult.c
> +++ b/testcases/realtime/func/matrix_mult/matrix_mult.c
> @@ -44,6 +44,7 @@
>  #include <libjvmsim.h>
>  #include <libstats.h>
> 
> +#define      MAX_CPUS        8192
>  #define PRIO         43
>  #define MATRIX_SIZE  100
>  #define DEF_OPS              8               /* the higher the number, the 
> more CPU intensive */
> @@ -70,6 +71,7 @@ static int *flags;
>  stats_container_t sdat, cdat, *curdat;
>  stats_container_t shist, chist;
>  static pthread_barrier_t mult_start;
> +static pthread_mutex_t mutex_cpu;
> 
>  int gettid(void)
>  {
> @@ -148,20 +150,28 @@ void matrix_mult_record(int m_size, int index)
>       curdat->records[index].y = delta;
>  }
> 
> -int set_affinity(int cpuid)
> +int set_affinity(int thread_id)

This argument seems pointless to me.  In main_thread, where you call
create_fifo_thread, you'll want to initialize the thread arguments to
NULL, rather than cpuid, because, as you've already established, it's
not guaranteed the CPU corresponding to that cpuid is actually online
until it is actually tested.  We can then get rid of the argument to
set_affinity all together and update all the callers.  Do you agree?

>  {
>       int tid = gettid();
>       cpu_set_t mask;
> +     static int cpuid = 0;
> +
> +     pthread_mutex_lock(&mutex_cpu);
> +     do {
> +             CPU_ZERO(&mask);
> +             CPU_SET(cpuid, &mask);
> +
> +             if (!sched_setaffinity(0, sizeof(mask), &mask)) {
> +                     printf ("Thread %d affinity set to 
> cpu%d\n",thread_id,cpuid);

thread_id != tid

Should probably also follow convention,

"Thread %d: Affinity set to..."

> +                     cpuid++;
> +                     pthread_mutex_unlock(&mutex_cpu);
> +                     return 0;
> +             }
> +     } while (++cpuid < MAX_CPUS);
> +     pthread_mutex_unlock(&mutex_cpu);
> 
> -     CPU_ZERO(&mask);
> -     CPU_SET(cpuid, &mask);
> -
> -     if (sched_setaffinity(0, sizeof(mask), &mask) < 0) {
> -             printf("Thread %d: Can't set affinity: %s\n", tid, 
> strerror(errno));
> -             exit(1);
> -     }
> -
> -     return 0;
> +     printf("Thread %d: Can't set affinity: %s\n", tid, strerror(errno));
> +     exit(1);
>  }
> 
>  void *concurrent_thread(void *thread)
-- 
-tim


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to