[PATCH] Implement getloadavg()
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Mar 20 15:40:00 GMT 2017
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20170320/3f22178d/attachment.sig>
More information about the Cygwin-patches
mailing list