Page MenuHomeFreeBSD

Add Linux compatibility support for `SC_NPROCESSORS_{CONF,ONLN}` as `_SC_NPROCESSORS_{CONF,ONLN}`
ClosedPublic

Authored by ngie on Sun, Dec 23, 11:28 PM.

Details

Summary

The goal of this change is to make it easier to use getconf to query
the number of available processors.

Sadly it's unclear per POSIX, which form (with a preceding _ or
lacking it) is correct. I will bring this up on the Austin Group list so
this point is clarified for implementors that might rely on this getconf
variable.

This is something I noticed when trying to import GoogleTest to FreeBSD
as one of the CI scripts uses this variable on Linux.

Test Plan

Setup:

$ make obj
$ make
$ cd $(make -V.OBJDIR)
  • Old form:
$ ./getconf _NPROCESSORS_ONLN
4
  • New (Linux compatible) form:
$ ./getconf NPROCESSORS_ONLN
4

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

ngie created this revision.Sun, Dec 23, 11:28 PM

Did you bring it up on the Austin Group list?

I'm also unclear about this change - you add the _ form, but the non-_ form is Linux compatible and already exists? Or is the comment above backwards?

ngie added a comment.EditedThu, Jan 10, 4:33 PM

Did you bring it up on the Austin Group list?

I'm also unclear about this change - you add the _ form, but the non-_ form is Linux compatible and already exists? Or is the comment above backwards?

FreeBSD supports SC_NPROCESSORS_CONF/SC_NPROCESSORS_ONLN (no leading underscore) prior to this change and Linux supports _SC_NPROCESSORS_CONF/_SC_NPROCESSORS_ONLN (leading underscore). Not having the latter form (for Linux) makes it trivially more difficult when porting software to FreeBSD today in bourne shell scripts.

I'm adding code to support the Linux way to remove that minor barrier, so people will be able to port to FreeBSD for free when using the right idiom on Linux.

The comment about the Austin Group list was to cause the committee to officially comment on (and make a decision) as to whether or not FreeBSD/Linux needs to support SC_NPROCESSORS_CONF or _SC_NPROCESSORS_CONF, etc.

ngie retitled this revision from Add Linux compatibility support for `_NPROCESSORS_{CONF,ONLN}` as `NPROCESSORS_{CONF,ONLN}` to Add Linux compatibility support for `NPROCESSORS_{CONF,ONLN}` as `_NPROCESSORS_{CONF,ONLN}`.Thu, Jan 10, 4:34 PM

@emaste: you're right though -- the summary was flip-flopped by accident :). Fixed!

ngie retitled this revision from Add Linux compatibility support for `NPROCESSORS_{CONF,ONLN}` as `_NPROCESSORS_{CONF,ONLN}` to Add Linux compatibility support for `SC_NPROCESSORS_{CONF,ONLN}` as `_SC_NPROCESSORS_{CONF,ONLN}`.Thu, Jan 10, 4:35 PM

the summary was flip-flopped by accident

Ah, makes sense now.

As for Austin Group I was just wondering if you brought it up there already (and if there's any response from them).

ngie added a comment.EditedThu, Jan 10, 4:44 PM

As for Austin Group I was just wondering if you brought it up there already (and if there's any response from them).

I haven't yet. I will be starting that conversation this week/next week.

jtl added a comment.Fri, Jan 11, 7:36 PM

Regardless of what the group says, it seems like we'll probably want to support both for a transitional period. Given that, this change seems OK. @emaste , do you agree?

emaste accepted this revision.Fri, Jan 11, 8:03 PM

Agreed

This revision is now accepted and ready to land.Fri, Jan 11, 8:03 PM
This revision was automatically updated to reflect the committed changes.