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

fix runqlen.py with 4.15 kernel #1510

Merged
merged 1 commit into from
Jan 4, 2018
Merged

fix runqlen.py with 4.15 kernel #1510

merged 1 commit into from
Jan 4, 2018

Conversation

yonghong-song
Copy link
Collaborator

The following kernel commit changes linux_src:kernel/sched/sched.h
struct cfs_rq structure:

commit 1ea6c46a23f1213d1972bfae220db5c165e27bba
Author: Peter Zijlstra <[email protected]>
Date:   Sat May 6 15:59:54 2017 +0200

    sched/fair: Propagate an effective runnable_load_avg

    The load balancer uses runnable_load_avg as load indicator. For
    !cgroup this is:

      runnable_load_avg = \Sum se->avg.load_avg ; where se->on_rq

    That is, a direct sum of all runnable tasks on that runqueue. As
    opposed to load_avg, which is a sum of all tasks on the runqueue,
    which includes a blocked component.
...

The commit is in kernel 4.15 release and will make current
runqlen.py internal cfs_rq_partial structure not syncing with the kernel one.
As a result, runqlen.py will produce incorrect results on 4.15.

This patch attempts to solve this issue by compiling a bpf program,
which accesses one of fields introduced by the above commit.
The successful compilation will indicate that we should amend
the cfs_rq_partial structure.

Signed-off-by: Yonghong Song [email protected]

The following kernel commit changes linux_src:kernel/sched/sched.h
struct cfs_rq structure:

```
commit 1ea6c46a23f1213d1972bfae220db5c165e27bba
Author: Peter Zijlstra <[email protected]>
Date:   Sat May 6 15:59:54 2017 +0200

    sched/fair: Propagate an effective runnable_load_avg

    The load balancer uses runnable_load_avg as load indicator. For
    !cgroup this is:

      runnable_load_avg = \Sum se->avg.load_avg ; where se->on_rq

    That is, a direct sum of all runnable tasks on that runqueue. As
    opposed to load_avg, which is a sum of all tasks on the runqueue,
    which includes a blocked component.
...
```

The commit is in kernel 4.15 release and will make current
runqlen.py internal cfs_rq_partial structure not syncing with the kernel one.
As a result, runqlen.py will produce incorrect results on 4.15.

This patch attempts to solve this issue by compiling a bpf program,
which accesses one of fields introduced by the above commit.
The successful compilation will indicate that we should amend
the cfs_rq_partial structure.

Signed-off-by: Yonghong Song <[email protected]>
@yonghong-song
Copy link
Collaborator Author

cc @brendangregg

@4ast 4ast merged commit 484e525 into master Jan 4, 2018
@brendangregg
Copy link
Member

Thanks @yonghong-song , I like the code comment!

ismhong pushed a commit to ismhong/bcc that referenced this pull request May 8, 2023
runqlen / cpuunclaimed add check_runnable_weight_field() as workaround to
check runnable_weight presents in struct cfs_rq in kernel/sched/sched.h by
trying to access runnable_weight field of struct
sched_entity in include/linux/sched.h. Please check more details in PR iovisor#1510
and iovisor#2164.

Unfortunately, the runnable_weight field of struct cfs_rq is removed, but the
runnable_weight field of struct sched_entity is remained by following patchset
series from Linux version 5.7.0.

- https://yhbt.net/lore/all/[email protected]/
- https://yhbt.net/lore/all/[email protected]/

Please also check the source of Linux below.

- include/linux/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/include/linux/sched.h#L475
- kernel/sched/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/kernel/sched/sched.h#L502

This PR checks runnable_weight field exists by using kernel_struct_has_field()
if target system with BTF enabled, otherwise fallback to legacy on-the-fly
compiling check. In the meantime, add Linux version 5.7.0 check in
structure definition cfs_rq_partial to prevent issue if target system
w/o BTF enabled and Linux version > 5.7.

Please check more details in iovisor#4602.

Signed-off-by: Ism Hong <[email protected]>
ismhong pushed a commit to ismhong/bcc that referenced this pull request May 8, 2023
runqlen / cpuunclaimed add check_runnable_weight_field() as workaround to
check runnable_weight presents in struct cfs_rq in kernel/sched/sched.h by
trying to access runnable_weight field of struct
sched_entity in include/linux/sched.h. Please check more details in PR iovisor#1510
and iovisor#2164.

Unfortunately, the runnable_weight field of struct cfs_rq is removed, but the
runnable_weight field of struct sched_entity is remained by following patchset
series from Linux version 5.7.0.

- https://yhbt.net/lore/all/[email protected]/
- https://yhbt.net/lore/all/[email protected]/

Please also check the source of Linux below.

- include/linux/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/include/linux/sched.h#L475
- kernel/sched/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/kernel/sched/sched.h#L502

This PR checks runnable_weight field exists by using kernel_struct_has_field()
if target system with BTF enabled, otherwise fallback to legacy on-the-fly
compiling check. In the meantime, add Linux version 5.7.0 check in
structure definition cfs_rq_partial to prevent issue if target system
w/o BTF enabled and Linux version > 5.7.

Please check more details in iovisor#4602.

Signed-off-by: Ism Hong <[email protected]>
ismhong pushed a commit to ismhong/bcc that referenced this pull request May 16, 2023
runqlen / cpuunclaimed add check_runnable_weight_field() as workaround to
check runnable_weight presents in struct cfs_rq in kernel/sched/sched.h by
trying to access runnable_weight field of struct
sched_entity in include/linux/sched.h. Please check more details in PR iovisor#1510
and iovisor#2164.

Unfortunately, the runnable_weight field of struct cfs_rq is removed, but the
runnable_weight field of struct sched_entity is remained by following patchset
series from Linux version 5.7.0.

- https://yhbt.net/lore/all/[email protected]/
- https://yhbt.net/lore/all/[email protected]/

Please also check the source of Linux below.

- include/linux/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/include/linux/sched.h#L475
- kernel/sched/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/kernel/sched/sched.h#L502

This PR checks runnable_weight field exists by using kernel_struct_has_field()
if target system with BTF enabled, otherwise fallback to legacy on-the-fly
compiling check. In the meantime, add Linux version 5.7.0 check in
structure definition cfs_rq_partial to prevent issue if target system
w/o BTF enabled and Linux version > 5.7.

Please check more details in iovisor#4602.

Signed-off-by: Ism Hong <[email protected]>
yonghong-song pushed a commit that referenced this pull request May 19, 2023
runqlen / cpuunclaimed add check_runnable_weight_field() as workaround to
check runnable_weight presents in struct cfs_rq in kernel/sched/sched.h by
trying to access runnable_weight field of struct
sched_entity in include/linux/sched.h. Please check more details in PR #1510
and #2164.

Unfortunately, the runnable_weight field of struct cfs_rq is removed, but the
runnable_weight field of struct sched_entity is remained by following patchset
series from Linux version 5.7.0.

- https://yhbt.net/lore/all/[email protected]/
- https://yhbt.net/lore/all/[email protected]/

Please also check the source of Linux below.

- include/linux/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/include/linux/sched.h#L475
- kernel/sched/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/kernel/sched/sched.h#L502

This PR checks runnable_weight field exists by using kernel_struct_has_field()
if target system with BTF enabled, otherwise fallback to legacy on-the-fly
compiling check. In the meantime, add Linux version 5.7.0 check in
structure definition cfs_rq_partial to prevent issue if target system
w/o BTF enabled and Linux version > 5.7.

Please check more details in #4602.

Signed-off-by: Ism Hong <[email protected]>
captain5050 pushed a commit to captain5050/bcc that referenced this pull request Oct 12, 2023
runqlen / cpuunclaimed add check_runnable_weight_field() as workaround to
check runnable_weight presents in struct cfs_rq in kernel/sched/sched.h by
trying to access runnable_weight field of struct
sched_entity in include/linux/sched.h. Please check more details in PR iovisor#1510
and iovisor#2164.

Unfortunately, the runnable_weight field of struct cfs_rq is removed, but the
runnable_weight field of struct sched_entity is remained by following patchset
series from Linux version 5.7.0.

- https://yhbt.net/lore/all/[email protected]/
- https://yhbt.net/lore/all/[email protected]/

Please also check the source of Linux below.

- include/linux/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/include/linux/sched.h#L475
- kernel/sched/sched.h
    - https://elixir.bootlin.com/linux/v5.7/source/kernel/sched/sched.h#L502

This PR checks runnable_weight field exists by using kernel_struct_has_field()
if target system with BTF enabled, otherwise fallback to legacy on-the-fly
compiling check. In the meantime, add Linux version 5.7.0 check in
structure definition cfs_rq_partial to prevent issue if target system
w/o BTF enabled and Linux version > 5.7.

Please check more details in iovisor#4602.

Signed-off-by: Ism Hong <[email protected]>
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.

3 participants