Page MenuHomeFreeBSD

cpuset: add --count
AbandonedPublic

Authored by mjg on Aug 25 2022, 8:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 22 2024, 7:08 PM
Unknown Object (File)
Mar 19 2024, 3:31 PM
Unknown Object (File)
Mar 19 2024, 3:13 PM
Unknown Object (File)
Jan 10 2024, 2:12 AM
Unknown Object (File)
Jan 6 2024, 6:20 AM
Unknown Object (File)
Dec 19 2023, 11:55 PM
Unknown Object (File)
Nov 28 2023, 5:07 PM
Unknown Object (File)
Nov 17 2023, 4:57 PM
Subscribers
None

Details

Summary
cpuset: add --count

Can be used to count the number hardware threads in the cpu set.

For example:
$ cpuset -g -p $$
pid 2440 mask: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39
pid 2440 domain policy: first-touch mask: 0, 1
$ cpuset -g --count -p $$
40

The intent is to replace calls to sysctl hw.ncpu and kern.smp.cpus which can be found in the tree.

I could not come up with a good letter, so added a long opt.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

mjg requested review of this revision.Aug 25 2022, 8:41 PM
mjg created this revision.
mjg edited the summary of this revision. (Show Details)
mjg edited the summary of this revision. (Show Details)
mjg added a reviewer: markj.

The name is confusing, in the cpuset documentation "thread" means software thread, not hardware thread. A plain --count would make more sense IMO.

The option doesn't compose with others well, why can't I do cpuset --count -g -d 0?

usr.bin/cpuset/cpuset.1
187

Why not allow a plain cpuset -g --threadcount?

usr.bin/cpuset/cpuset.c
312

No need for a lone return; here.

I don't care for the name, but indeed the word thread is overloaded. Perhaps hwthread?

Anyhow the patch only allows the bare minimum I need for the feature to be usable, while explicitly disallowing everything else so that I don't have to test it. Should the need arise to expand it, it can be done without breaking the current usage.

mjg retitled this revision from cpuset: add --threadcount to cpuset: add --count.
mjg edited the summary of this revision. (Show Details)
  • rename the opt to --count
  • drop return

I think implementing it as another sub-flag of -g is even simpler. No need to check if (Cflag || cflag || dflag || iflag || jflag || lflag || nflag || rflag || sflag || tflag || xflag). I wrote a similar patch in D36390 to demonstrate.

I noted the primary point of the patch to is to replace uses like sysctl -n hw.ncpu and similar, which is precisely why it only outputs a number without any extra stuff. I don't care if this is a one-letter subflag for g, I do care about not being verbose.

In D36351#826415, @mjg wrote:

I noted the primary point of the patch to is to replace uses like sysctl -n hw.ncpu and similar, which is precisely why it only outputs a number without any extra stuff. I don't care if this is a one-letter subflag for g, I do care about not being verbose.

I added a flag to strip the headers, akin to sysctl -n. So cpuset -gHN does what you want.

this is no longer needed then.

D36390