public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
* Implement sched_[gs]etaffinity()
@ 2019-04-11  4:21 Mark Geisert
  2019-04-11  8:26 ` Corinna Vinschen
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Geisert @ 2019-04-11  4:21 UTC (permalink / raw)
  To: cygwin-developers

I've recently sent a patch to cygwin-patches that implements these 
Linux-specific functions.  I used the following test program to debug and test 
the implementation.  When the program is run, you can watch it migrate from CPU 
to CPU with Windows Task Manager.

I've only tested on 64-bit Windows 7 so far.  If the code (in the patch) is 
adequate I will supply another patch for doc updates, etc.

..mark

P.S. Here's the test program:

~ cat afftest.c
#define _GNU_SOURCE
#include <errno.h>
#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "/oss/src/newlib/libc/include/sched.h" //XXX for demo only

size_t cpusetsize;
volatile int nprocs;
volatile int proc;

void handler (int unused)
{
   char buf[2] = "\000";
   cpu_set_t mask;

   ++proc;
   if (proc >= nprocs)
     proc = 0;
   buf[0] = '0' + proc;
   write (2, buf, 1);

   mask = 1 << proc;
   int res = sched_setaffinity (0, cpusetsize, &mask);
   if (res < 0)
     {
       perror ("handler");
       exit (2);
     }
   alarm (8);
}

int
main (int argc, char **argv)
{
   char *ptr = getenv ("NUMBER_OF_PROCESSORS");

   if (!ptr)
     return 1;
   nprocs = atoi (ptr);
   proc = nprocs;
   cpusetsize = (nprocs + 7) / 8;

   signal (SIGALRM, handler);
   alarm (1);

   double x = 92837492873.2398749827394723984723;
   while (x++)
     x = sqrt (x), x *= x;
}

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-04-26  8:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-11  4:21 Implement sched_[gs]etaffinity() Mark Geisert
2019-04-11  8:26 ` Corinna Vinschen
2019-04-11  8:38   ` Corinna Vinschen
2019-04-11 20:52     ` Mark Geisert
2019-04-12  7:46       ` Corinna Vinschen
2019-04-16  8:19         ` Mark Geisert
2019-04-16 10:45           ` Corinna Vinschen
2019-04-17  4:31             ` Mark Geisert
2019-04-17  7:57               ` Corinna Vinschen
2019-04-26  8:44                 ` Mark Geisert
2019-04-26  8:53                   ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).