Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't include offline CPUs in summary for OpenBSD #580

Closed
wants to merge 1 commit into from
Closed

don't include offline CPUs in summary for OpenBSD #580

wants to merge 1 commit into from

Conversation

sthen
Copy link
Contributor

@sthen sthen commented Mar 27, 2021

By default, OpenBSD disables SMT (hyperthreading) cpu pseudo-cores.
This can be changed at runtime by setting the hw.smt sysctl so they
may become active later, therefore they are still present in cpu
stat structures but are marked as offline.

As done with native top(1), this drops them from the cpu summary
graphs.

@BenBE
Copy link
Member

BenBE commented Mar 28, 2021

Can you squash your commits? Makes the history cleaner and easier to follow.

@sthen
Copy link
Contributor Author

sthen commented Mar 29, 2021 via email

@BenBE
Copy link
Member

BenBE commented Mar 29, 2021

When on your branch:

# Fetch latest changes
git fetch --all

# Apply latest changes
git pull --rebase your-repo your-branch

# Base local changes on upstream master
git rebase -i htop-upstream/master

# Push the modified branch to your repo to update this PR.
git push --force-with-lease your-repo your-branch

In the editor that opens change the second line from pick to fixup. See also the notes given in the descriptive text in that editor.


if (cpu_index_c == pl->cpuCount)
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this loop about?
cpu_index_c is being increased and the loop is aborted when it reaches a specific value, but there are no further implications.

Copy link
Contributor Author

@sthen sthen Apr 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like I missed a bit when I was merging the patch which was originally done against 3.0.1. It will work on Intel CPUs without that loop (the skipped cpus are the higher numbered ones) but they're interspersed on AMD (skipped would be 1,3,5,7,..) I just pushed an updated version that I think should do the trick (I don't have an AMD cpu with SMT to test that part with though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked someone to test on AMD, this version is looking ok.

@@ -53,6 +57,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
pl->cpuCount = 1;
}
opl->cpus = xCalloc(pl->cpuCount + 1, sizeof(CPUData));
opl->cpuIndex = xRealloc(opl->cpuIndex, pl->cpuCount * sizeof(int));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*opl was initialized in this function, no need to realloc (just malloc (or calloc, see later comment))

size = sizeof(cpu_stats);
for (unsigned int i = 0; i < ncpu; i++) {
ncmib[2] = i;
sysctl(ncmib, 3, &cpu_stats, &size, NULL, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check for a sysctl failure

@@ -43,7 +43,7 @@ typedef struct OpenBSDProcessList_ {

CPUData* cpus;
int cpuSpeed;

int* cpuIndex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe include the index in the CPUData struct (the one unused int of the average entry is negligible)

By default, OpenBSD disables SMT (hyperthreading) cpu pseudo-cores.
This can be changed at runtime by setting the hw.smt sysctl so they
may become active later, therefore they are still present in cpu
stat structures but are marked as offline.

As done with native top(1), this drops them from the cpu summary
graphs.
@@ -76,6 +86,21 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui

opl->cpuSpeed = -1;

size = sizeof(cpu_stats);
for (unsigned int i = 0; i < ncpu; i++) {
ncmib[2] = i;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move actual initialization of ncmib here and make it const.

Suggested change
ncmib[2] = i;
const int ncmib[] = { CTL_KERN, KERN_CPUSTATS, i };

int r;
unsigned int cpu_index_c = 0, ncpu;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single variable per line …

size = sizeof(cpu_stats);
for (unsigned int i = 0; i < ncpu; i++) {
ncmib[2] = i;
if (sysctl(ncmib, 3, &cpu_stats, &size, NULL, 0) < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't size be re-initialized inside the loop?

@sthen
Copy link
Contributor Author

sthen commented Apr 18, 2021

Since you have a pretty clear idea of what changes you want, could one of you fix it up please? Most of my development work is with OpenBSD and we don't use git so what is probably a 2 minute job for you takes me about half an hour each time to figure out how to rebase the commit history how you want it. Thanks!

@BenBE BenBE added BSD 🐡 Issues related to *BSD bug 🐛 Something isn't working enhancement Extension or improvement to existing feature labels Apr 18, 2021
@BenBE BenBE added this to the 3.0.6 milestone Apr 18, 2021
@cgzones
Copy link
Member

cgzones commented Apr 18, 2021

Applied with adjustments via feec16c.
Thanks for your contribution.

@cgzones cgzones closed this Apr 18, 2021
@sthen
Copy link
Contributor Author

sthen commented Apr 18, 2021

Many thanks.

@sthen sthen deleted the openbsd_cpuonline branch April 18, 2021 19:41
cgzones added a commit to cgzones/htop that referenced this pull request Jun 12, 2021
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: htop-dev#650
Related: htop-dev#580
cgzones added a commit to cgzones/htop that referenced this pull request Jun 12, 2021
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: htop-dev#650
Related: htop-dev#580
cgzones added a commit to cgzones/htop that referenced this pull request Jun 12, 2021
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: htop-dev#650
Related: htop-dev#580
@cgzones cgzones mentioned this pull request Jun 12, 2021
8 tasks
cgzones added a commit to cgzones/htop that referenced this pull request Jun 12, 2021
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: htop-dev#650
Related: htop-dev#580
cgzones added a commit to cgzones/htop that referenced this pull request Jun 13, 2021
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: htop-dev#650
Related: htop-dev#580
BenBE pushed a commit to cgzones/htop that referenced this pull request Jul 18, 2021
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: htop-dev#650
Related: htop-dev#580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BSD 🐡 Issues related to *BSD bug 🐛 Something isn't working enhancement Extension or improvement to existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants