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

Procfs enhancements #1066

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Procfs enhancements #1066

wants to merge 7 commits into from

Conversation

nimelehin
Copy link
Contributor

@nimelehin nimelehin commented Nov 16, 2020

What's added:

  • Add api to collect statistics on which tasks are blocked
  • Add /proc/loadavg
  • Fixing /proc/stat to make htop working
  • Add apis to get cpus usage (Linux & Darwin)

Closes #273

@nimelehin nimelehin marked this pull request as draft November 16, 2020 16:12
@nimelehin
Copy link
Contributor Author

nimelehin commented Nov 18, 2020

Hello @tbodt! Asking you to review these changes, they make htop working and also extend procfs.

The patches can collect statistics on which tasks are blocked. This is done using a special wrapper in zones which can block our code (e.g calling real's os syscall). The wrapper is implemented with for which looks strange at first glance, but I've checked that compiler can easily unroll this loop, so no performance degradation and it looks nice in C, I think.

Also updated procfs, so htop no longer freezing.
Screenshot 2020-11-18 at 17 07 02

@nimelehin nimelehin marked this pull request as ready for review November 18, 2020 14:08
@nimelehin
Copy link
Contributor Author

Seems it closes #273

@nimelehin nimelehin changed the title WIP: Procfs enhancements Procfs enhancements Nov 18, 2020
@tbodt
Copy link
Member

tbodt commented Dec 6, 2020

Thanks for the PR! The one thing I'm not sure about is the blocking regions, as that's a pretty large code change and it's easy to miss a spot. I guess nothing really bad happens if you do, though.

Copy link
Member

@tbodt tbodt left a comment

Choose a reason for hiding this comment

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

A slight problem here is some of these stats are for the whole system including any iOS daemons that are running and some of these stats are only for processes running inside iSH. This could get a bit confusing in htop if you can see CPU usage for everything but only see some processes in the breakdown. It's probably fine though.

kernel/task.h Outdated Show resolved Hide resolved
kernel/task.h Outdated Show resolved Hide resolved
kernel/task.h Outdated Show resolved Hide resolved
kernel/signal.c Outdated
@@ -636,8 +636,10 @@ int_t sys_rt_sigsuspend(addr_t mask_addr, uint_t size) {

int_t sys_pause() {
lock(&current->sighand->lock);
while (wait_for(&current->pause, &current->sighand->lock, NULL) != _EINTR)
continue;
TASK_BLOCKING_AREA {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this, it would make more sense to put the blocking area inside of wait_for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately this might bring a deadlock. I just want this blocking defines as simple as possible, so I just put them on the most of blocking syscalls in Linux (list of blocking sys calls). From this list only fcntl and close are not wrapped with TASK_MAY_BLOCK, since their implementation in our case is not blocking.

Copy link
Member

@tbodt tbodt Dec 7, 2020

Choose a reason for hiding this comment

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

This list seems outdated? It doesn't include futex or sigsuspend, for example.

kernel/fs.c Outdated Show resolved Hide resolved
fs/proc/root.c Outdated Show resolved Hide resolved
@nimelehin nimelehin force-pushed the procfs branch 2 times, most recently from 18e7f68 to 856e13a Compare December 7, 2020 19:11
@emkey1
Copy link
Contributor

emkey1 commented Dec 9, 2020

As an FYI, this mostly fixes the procps top command as well. The memory number looks extremely bogus.

IMG_0110

Add apis to collect statisctics on blocked tasks. A scpecial wrapper
should be used in areas which may block a task.
@nimelehin
Copy link
Contributor Author

@tbodt, hello. I made these changes:

  • Loading per cpu usage
  • List of alive pids
  • More TASK_MAY_BLOCK

@nimelehin nimelehin requested a review from tbodt December 10, 2020 16:01
Updated /proc/stat to be compatible with Linux's implementation.
@62f 62f mentioned this pull request Feb 17, 2021
emkey1 pushed a commit to emkey1/ish-AOK that referenced this pull request Dec 27, 2021
emkey1 pushed a commit to emkey1/ish-AOK that referenced this pull request Dec 27, 2021
@rbreaves
Copy link

rbreaves commented Aug 7, 2022

Can we get this merged? htop is broken till it is..

@emkey1
Copy link
Contributor

emkey1 commented Aug 7, 2022

The reliance on locking/unlocking pids_lock in the TASK_MAY_BLOCK macro is a bit problematic from a performance/reliability perspective as so many other parts of iSH use it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

htop does not run
4 participants