This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Implement getloadavg()


On Mar 20 15:04, Jon Turney wrote:
> On 20/03/2017 10:37, Corinna Vinschen wrote:
> > On Mar 17 17:50, Jon Turney wrote:
> > The load average is global, non-critical data.  So what about storing it
> > in shared_info instead?  This way, only the first call of the first
> > Cygwin process returns all zero.
> 
> Ok.
> 
> > > +static bool load_init (void)
> > > +{
> > > +  static bool tried = false;
> > > +  static bool initialized = false;
> > > +
> > > +  if (!tried) {
> > > +    tried = true;
> > > +
> > > +    if ((PdhOpenQueryA (NULL, 0, &query) == ERROR_SUCCESS) &&
> > > +	(PdhAddEnglishCounterA (query, "\\Processor(_Total)\\% Processor Time",
> > > +				0, &counter1) == ERROR_SUCCESS) &&
> > > +	(PdhAddEnglishCounterA (query, "\\System\\Processor Queue Length",
> > > +				0, &counter2) == ERROR_SUCCESS)) {
> > > +      initialized = true;
> > > +    } else {
> > > +      debug_printf("loadavg PDH initialization failed\n");
> > > +    }
> > > +  }
> > > +
> > > +  return initialized;
> > > +}
> > 
> > How slow is that initialization?  Would it {make sense|hurt} to call it
> > once in the initalization of Cygwin's shared mem in shared_info::initialize?
> 
> I don't think that's particularly heavyweight, and I didn't see anything to
> suggest that PDH query handles can be shared between processes, but I'll
> look into it.

Oh, right, that might pose a problem.

But even then:

The first process creating shared_info could call this and prime the values
with a first call to getloadavg.  Each other process would have to init its
own pointers.  You just have to make sure that access to the loadavg values
from shared_info is atomic.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]