Open11

try delay accounting

KumassyKumassy

https://www.kimullaa.com/posts/202112072130/

を参考に source code をダウンロードする

delay accounting は有効化されている

ubuntu@kumachine-cloud:~$ cat /boot/config-6.2.0-1012-aws | grep -E "DELAY_ACCT|TASKSTATS"
CONFIG_TASKSTATS=y
CONFIG_TASK_DELAY_ACCT=y
ubuntu@kumachine-cloud:~$ sudo apt-get source linux-image-$(uname -r)
Reading package lists... Done
E: You must put some 'deb-src' URIs in your sources.list

deb-src を有効化する

ubuntu@kumachine-cloud:~$ sudo vim /etc/apt/sources.list
ubuntu@kumachine-cloud:~$ sudo cat /etc/apt/sources.list
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy main restricted
deb-src http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy main restricted
# ↑編集

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted
deb-src http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted
# ↑編集

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy universe
# deb-src http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy universe
deb http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-updates universe
# deb-src http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy multiverse
# deb-src http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy multiverse
deb http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-updates multiverse
# deb-src http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted universe multiverse

deb http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports jammy-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports jammy-security universe
deb http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse
ubuntu@kumachine-cloud:~$ sudo apt update
Hit:1 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease
Hit:2 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports jammy InRelease
Hit:3 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports jammy-updates InRelease
Hit:4 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports jammy-backports InRelease
Get:5 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports jammy-updates/restricted Sources [49.7 kB]
Get:6 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports jammy-updates/main Sources [448 kB]
Fetched 498 kB in 3s (195 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
49 packages can be upgraded. Run 'apt list --upgradable' to see them.

なんかエラーが出た

ubuntu@kumachine-cloud:~$ sudo apt-get source linux-image-$(uname -r)
Reading package lists... Done
Picking 'linux-signed-aws-6.2' as source package instead of 'linux-image-6.2.0-1012-aws'
Need to get 15.5 kB of source archives.
Get:1 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports jammy-updates/main linux-signed-aws-6.2 6.2.0-1015.15~22.04.1 (dsc) [1962 B]
Get:2 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports jammy-updates/main linux-signed-aws-6.2 6.2.0-1015.15~22.04.1 (tar) [13.6 kB]
Fetched 15.5 kB in 1s (21.3 kB/s)
sh: 1: dpkg-source: not found
W: Download is performed unsandboxed as root as file 'linux-signed-aws-6.2_6.2.0-1015.15~22.04.1.dsc' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
E: Unpack command 'dpkg-source --no-check -x linux-signed-aws-6.2_6.2.0-1015.15~22.04.1.dsc' failed.
N: Check if the 'dpkg-dev' package is installed.
KumassyKumassy

必要なパッケージをインストールする

ubuntu@kumachine-cloud:~$ sudo apt install -y dpkg-dev

ubuntu@kumachine-cloud:~$ sudo apt-get source linux-image-$(uname -r)
Reading package lists... Done
Picking 'linux-signed-aws-6.2' as source package instead of 'linux-image-6.2.0-1012-aws'
Skipping already downloaded file 'linux-signed-aws-6.2_6.2.0-1015.15~22.04.1.dsc'
Skipping already downloaded file 'linux-signed-aws-6.2_6.2.0-1015.15~22.04.1.tar.xz'
Need to get 0 B of source archives.
dpkg-source: info: extracting linux-signed-aws-6.2 in linux-signed-aws-6.2-6.2.0
dpkg-source: info: unpacking linux-signed-aws-6.2_6.2.0-1015.15~22.04.1.tar.xz

ubuntu@kumachine-cloud:~$ ls
linux-signed-aws-6.2-6.2.0  linux-signed-aws-6.2_6.2.0-1015.15~22.04.1.dsc  linux-signed-aws-6.2_6.2.0-1015.15~22.04.1.tar.xz

ダウンロードできたが、中身をみてもソースコードっぽいファイルは見当たらない

KumassyKumassy

https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel をみてソースコードをダウンロードする

ubuntu@kumachine-cloud:~$ apt-get source linux-image-unsigned-$(uname -r)
Reading package lists... Done
Picking 'linux-aws-6.2' as source package instead of 'linux-image-unsigned-6.2.0-1012-aws'
NOTICE: 'linux-aws-6.2' packaging is maintained in the 'Git' version control system at:
git://git.launchpad.net/~canonical-kernel/ubuntu/+source/linux-aws/+git/jammy
Please use:
git clone git://git.launchpad.net/~canonical-kernel/ubuntu/+source/linux-aws/+git/jammy
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 227 MB of source archives.





ubuntu@kumachine-cloud:~$ ls
linux-aws-6.2-6.2.0  linux-aws-6.2_6.2.0-1015.15~22.04.1.diff.gz  linux-aws-6.2_6.2.0-1015.15~22.04.1.dsc  linux-aws-6.2_6.2.0.orig.tar.gz

ダウンロードできたっぽい

KumassyKumassy

ただし、ビルドに失敗してしまう

ubuntu@kumachine-cloud:~$ sudo make -C linux-aws-6.2-6.2.0/tools/accounting/
make: Entering directory '/home/ubuntu/linux-aws-6.2-6.2.0/tools/accounting'
gcc -I../../usr/include    getdelays.c   -o getdelays
getdelays.c: In function ‘print_delayacct’:
getdelays.c:236:39: error: ‘struct taskstats’ has no member named ‘compact_count’; did you mean ‘cpu_count’?
  236 |                (unsigned long long)t->compact_count,
      |                                       ^~~~~~~~~~~~~
      |                                       cpu_count
getdelays.c:237:39: error: ‘struct taskstats’ has no member named ‘compact_delay_total’; did you mean ‘cpu_delay_total’?
  237 |                (unsigned long long)t->compact_delay_total,
      |                                       ^~~~~~~~~~~~~~~~~~~
      |                                       cpu_delay_total
getdelays.c:238:30: error: ‘struct taskstats’ has no member named ‘compact_delay_total’; did you mean ‘cpu_delay_total’?
  238 |                average_ms(t->compact_delay_total, t->compact_count),
      |                              ^~~~~~~~~~~~~~~~~~~
getdelays.c:194:27: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                           ^
getdelays.c:238:54: error: ‘struct taskstats’ has no member named ‘compact_count’; did you mean ‘cpu_count’?
  238 |                average_ms(t->compact_delay_total, t->compact_count),
      |                                                      ^~~~~~~~~~~~~
getdelays.c:194:45: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                             ^
getdelays.c:238:54: error: ‘struct taskstats’ has no member named ‘compact_count’; did you mean ‘cpu_count’?
  238 |                average_ms(t->compact_delay_total, t->compact_count),
      |                                                      ^~~~~~~~~~~~~
getdelays.c:194:49: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                                 ^
getdelays.c:240:39: error: ‘struct taskstats’ has no member named ‘wpcopy_count’; did you mean ‘cpu_count’?
  240 |                (unsigned long long)t->wpcopy_count,
      |                                       ^~~~~~~~~~~~
      |                                       cpu_count
getdelays.c:241:39: error: ‘struct taskstats’ has no member named ‘wpcopy_delay_total’; did you mean ‘cpu_delay_total’?
  241 |                (unsigned long long)t->wpcopy_delay_total,
      |                                       ^~~~~~~~~~~~~~~~~~
      |                                       cpu_delay_total
getdelays.c:242:30: error: ‘struct taskstats’ has no member named ‘wpcopy_delay_total’; did you mean ‘cpu_delay_total’?
  242 |                average_ms(t->wpcopy_delay_total, t->wpcopy_count));
      |                              ^~~~~~~~~~~~~~~~~~
getdelays.c:194:27: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                           ^
getdelays.c:242:53: error: ‘struct taskstats’ has no member named ‘wpcopy_count’; did you mean ‘cpu_count’?
  242 |                average_ms(t->wpcopy_delay_total, t->wpcopy_count));
      |                                                     ^~~~~~~~~~~~
getdelays.c:194:45: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                             ^
getdelays.c:242:53: error: ‘struct taskstats’ has no member named ‘wpcopy_count’; did you mean ‘cpu_count’?
  242 |                average_ms(t->wpcopy_delay_total, t->wpcopy_count));
      |                                                     ^~~~~~~~~~~~
getdelays.c:194:49: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                                 ^
make: *** [<builtin>: getdelays] Error 1
make: Leaving directory '/home/ubuntu/linux-aws-6.2-6.2.0/tools/accounting'
KumassyKumassy

https://docs.kernel.org/accounting/delay-accounting.html#usage をみると

Delay accounting is disabled by default at boot up. To enable, add:
delayacct
to the kernel boot options.

とある。一方で

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.2.0-1012-aws root=PARTUUID=69e1997e-a903-4643-a4fa-491f49342e1c ro console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 panic=-1

となっていて delayacct がついていなさそう

KumassyKumassy

https://wiki.archlinux.jp/index.php/カーネルパラメータ
を参考に delayacct つきで起動する

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ sudo vim /etc/default/grub
ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ sudo cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash delayacct" # ここを編集
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"


ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ sudo update-grub2
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/40-force-partuuid.cfg'
Sourcing file `/etc/default/grub.d/50-cloudimg-settings.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
GRUB_FORCE_PARTUUID is set, will attempt initrdless boot
Found linux image: /boot/vmlinuz-6.2.0-1012-aws
Found initrd image: /boot/initrd.img-6.2.0-1012-aws
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

reboot

あれーかわってない?

ubuntu@kumachine-cloud:~$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.2.0-1012-aws root=PARTUUID=69e1997e-a903-4643-a4fa-491f49342e1c ro console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 panic=-1

ubuntu@kumachine-cloud:~$ cat /boot/grub/grub.cfg | grep delay
KumassyKumassy

ここで上書きされてた

ubuntu@kumachine-cloud:~$ cat /etc/default/grub.d/50-cloudimg-settings.cfg
# Cloud Image specific Grub settings for Generic Cloud Images
# CLOUD_IMG: This file was created/modified by the Cloud Image build process

# Set the recordfail timeout
GRUB_RECORDFAIL_TIMEOUT=0

# Do not wait on grub prompt
GRUB_TIMEOUT=0

# Set the default commandline
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295"

# Set the grub console type
GRUB_TERMINAL=console
GRUB_HIDDEN_TIMEOUT=0.1

編集する

ubuntu@kumachine-cloud:~$ sudo vim /etc/default/grub.d/50-cloudimg-settings.cfg
ubuntu@kumachine-cloud:~$ sudo cat /etc/default/grub.d/50-cloudimg-settings.cfg
# Cloud Image specific Grub settings for Generic Cloud Images
# CLOUD_IMG: This file was created/modified by the Cloud Image build process

# Set the recordfail timeout
GRUB_RECORDFAIL_TIMEOUT=0

# Do not wait on grub prompt
GRUB_TIMEOUT=0

# Set the default commandline
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 delayacct"

# Set the grub console type
GRUB_TERMINAL=console
GRUB_HIDDEN_TIMEOUT=0.1


ubuntu@kumachine-cloud:~$ sudo update-grub2
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/40-force-partuuid.cfg'
Sourcing file `/etc/default/grub.d/50-cloudimg-settings.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
GRUB_FORCE_PARTUUID is set, will attempt initrdless boot
Found linux image: /boot/vmlinuz-6.2.0-1012-aws
Found initrd image: /boot/initrd.img-6.2.0-1012-aws
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

よさそう

ubuntu@kumachine-cloud:~$ cat /boot/grub/grub.cfg | grep 'delay'
	  linux	/boot/vmlinuz-6.2.0-1012-aws root=PARTUUID=69e1997e-a903-4643-a4fa-491f49342e1c ro  console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 delayacct
	  linux	/boot/vmlinuz-6.2.0-1012-aws root=PARTUUID=69e1997e-a903-4643-a4fa-491f49342e1c ro  console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 delayacct panic=-1
		  linux	/boot/vmlinuz-6.2.0-1012-aws root=PARTUUID=69e1997e-a903-4643-a4fa-491f49342e1c ro  console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 delayacct
		  linux	/boot/vmlinuz-6.2.0-1012-aws root=PARTUUID=69e1997e-a903-4643-a4fa-491f49342e1c ro  console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 delayacct panic=-1

reboot

たしかに delayacct パラメータ付きでカーネルを起動できた

ubuntu@kumachine-cloud:~$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.2.0-1012-aws root=PARTUUID=69e1997e-a903-4643-a4fa-491f49342e1c ro console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 delayacct panic=-1
ubuntu@kumachine-cloud:~$

ただしコンパイルは通らない

ubuntu@kumachine-cloud:~$ sudo make -C linux-aws-6.2-6.2.0/tools/accounting/
make: Entering directory '/home/ubuntu/linux-aws-6.2-6.2.0/tools/accounting'
gcc -I../../usr/include    getdelays.c   -o getdelays
getdelays.c: In function ‘print_delayacct’:
getdelays.c:236:39: error: ‘struct taskstats’ has no member named ‘compact_count’; did you mean ‘cpu_count’?
  236 |                (unsigned long long)t->compact_count,
      |                                       ^~~~~~~~~~~~~
      |                                       cpu_count
getdelays.c:237:39: error: ‘struct taskstats’ has no member named ‘compact_delay_total’; did you mean ‘cpu_delay_total’?
  237 |                (unsigned long long)t->compact_delay_total,
      |                                       ^~~~~~~~~~~~~~~~~~~
      |                                       cpu_delay_total
getdelays.c:238:30: error: ‘struct taskstats’ has no member named ‘compact_delay_total’; did you mean ‘cpu_delay_total’?
  238 |                average_ms(t->compact_delay_total, t->compact_count),
      |                              ^~~~~~~~~~~~~~~~~~~
getdelays.c:194:27: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                           ^
getdelays.c:238:54: error: ‘struct taskstats’ has no member named ‘compact_count’; did you mean ‘cpu_count’?
  238 |                average_ms(t->compact_delay_total, t->compact_count),
      |                                                      ^~~~~~~~~~~~~
getdelays.c:194:45: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                             ^
getdelays.c:238:54: error: ‘struct taskstats’ has no member named ‘compact_count’; did you mean ‘cpu_count’?
  238 |                average_ms(t->compact_delay_total, t->compact_count),
      |                                                      ^~~~~~~~~~~~~
getdelays.c:194:49: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                                 ^
getdelays.c:240:39: error: ‘struct taskstats’ has no member named ‘wpcopy_count’; did you mean ‘cpu_count’?
  240 |                (unsigned long long)t->wpcopy_count,
      |                                       ^~~~~~~~~~~~
      |                                       cpu_count
getdelays.c:241:39: error: ‘struct taskstats’ has no member named ‘wpcopy_delay_total’; did you mean ‘cpu_delay_total’?
  241 |                (unsigned long long)t->wpcopy_delay_total,
      |                                       ^~~~~~~~~~~~~~~~~~
      |                                       cpu_delay_total
getdelays.c:242:30: error: ‘struct taskstats’ has no member named ‘wpcopy_delay_total’; did you mean ‘cpu_delay_total’?
  242 |                average_ms(t->wpcopy_delay_total, t->wpcopy_count));
      |                              ^~~~~~~~~~~~~~~~~~
getdelays.c:194:27: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                           ^
getdelays.c:242:53: error: ‘struct taskstats’ has no member named ‘wpcopy_count’; did you mean ‘cpu_count’?
  242 |                average_ms(t->wpcopy_delay_total, t->wpcopy_count));
      |                                                     ^~~~~~~~~~~~
getdelays.c:194:45: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                             ^
getdelays.c:242:53: error: ‘struct taskstats’ has no member named ‘wpcopy_count’; did you mean ‘cpu_count’?
  242 |                average_ms(t->wpcopy_delay_total, t->wpcopy_count));
      |                                                     ^~~~~~~~~~~~
getdelays.c:194:49: note: in definition of macro ‘average_ms’
  194 | #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1))
      |                                                 ^
make: *** [<builtin>: getdelays] Error 1
make: Leaving directory '/home/ubuntu/linux-aws-6.2-6.2.0/tools/accounting'
```****
KumassyKumassy
ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ gcc -I../../usr/include    getdelays.c   -E

で preprocess 後のコードをみる

# 41 "/usr/include/linux/taskstats.h" 3 4
struct taskstats {




 __u64 nvcsw;
 __u64 nivcsw;


 __u64 ac_utimescaled;
 __u64 ac_stimescaled;
 __u64 cpu_scaled_run_real_total;


 __u64 freepages_count;
 __u64 freepages_delay_total;


 __u64 thrashing_count;
 __u64 thrashing_delay_total;


 __u64 ac_btime64;
};

となっており v10 までの fields しか存在しない
https://elixir.bootlin.com/linux/v6.2/source/include/uapi/linux/taskstats.h#L217

apt-get source したファイルでは

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ cat ~/linux-aws-6.2-6.2.0/include/uapi/linux/taskstats.h


#define TASKSTATS_VERSION	13
#define TS_COMM_LEN		32	/* should be >= TASK_COMM_LEN
					 * in linux/sched.h */

struct taskstats {

	/* v10: 64-bit btime to avoid overflow */
	__u64	ac_btime64;		/* 64-bit begin time */

	/* v11: Delay waiting for memory compact */
	__u64	compact_count;
	__u64	compact_delay_total;

	/* v12 begin */
	__u32   ac_tgid;	/* thread group ID */
	/* Thread group walltime up to now. This is total process walltime if
	 * AGROUP flag is set.
	 */
	__u64	ac_tgetime __attribute__((aligned(8)));
	/* Lightweight information to identify process binary files.
	 * This leaves userspace to match this to a file system path, using
	 * MAJOR() and MINOR() macros to identify a device and mount point,
	 * the inode to identify the executable file. This is /proc/self/exe
	 * at the end, so matching the most recent exec(). Values are zero
	 * for kernel threads.
	 */
	__u64   ac_exe_dev;     /* program binary device ID */
	__u64   ac_exe_inode;   /* program binary inode number */
	/* v12 end */

	/* v13: Delay waiting for write-protect copy */
	__u64    wpcopy_count;
	__u64    wpcopy_delay_total;
};

となってて v13 まであるのだが...

KumassyKumassy

よくみると usr/include が空になっている

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0$ find usr/include/
usr/include/
usr/include/.gitignore
usr/include/headers_check.pl
usr/include/Makefile

Makefile を眺め

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0$ make help | grep header
  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH
  includecheck    - Check for duplicate included header files
  headerdep       - Detect inclusion cycles in headers
ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0$ make headers_install
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/unifdef

これでファイルができた

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0$ find usr/include/
usr/include/
usr/include/mtd
usr/include/mtd/ubi-user.h
usr/include/mtd/mtd-abi.h
usr/include/mtd/.nftl-user.h.cmd
usr/include/mtd/.ubi-user.h.cmd
usr/include/mtd/inftl-user.h
usr/include/mtd/.mtd-abi.h.cmd
usr/include/mtd/.inftl-user.h.cmd
usr/include/mtd/.mtd-user.h.cmd
usr/include/mtd/mtd-user.h

gcc -E すると ~/linux-aws-6.2-6.2.0/usr/include が参照されるようになったことがわかる

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ gcc -I../../usr/include    getdelays.c   -E | grep taskstats
# 1 "../../usr/include/linux/taskstats.h" 1
# 41 "../../usr/include/linux/taskstats.h"
struct taskstats {
# 73 "../../usr/include/linux/taskstats.h"
# 133 "../../usr/include/linux/taskstats.h"
# 210 "../../usr/include/linux/taskstats.h"
static void print_delayacct(struct taskstats *t)
static void task_context_switch_counts(struct taskstats *t)
static void print_ioacct(struct taskstats *t)
       print_delayacct((struct taskstats *) ((void *)((char*)(na) + ((int) (((sizeof(struct nlattr)) + 4 - 1) & ~(4 - 1))))));
       print_ioacct((struct taskstats *) ((void *)((char*)(na) + ((int) (((sizeof(struct nlattr)) + 4 - 1) & ~(4 - 1))))));
       task_context_switch_counts((struct taskstats *) ((void *)((char*)(na) + ((int) (((sizeof(struct nlattr)) + 4 - 1) & ~(4 - 1))))));

make できた

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ make
gcc -I../../usr/include    getdelays.c   -o getdelays
gcc -I../../usr/include    procacct.c   -o procacct

getdelays が動いた

ubuntu@kumachine-cloud:~/linux-aws-6.2-6.2.0/tools/accounting$ sudo ./getdelays -p 589 -d
print delayacct stats ON
PID	589


CPU             count     real total  virtual total    delay total  delay average
                   13        8000000       14010756        8673476          0.667ms
IO              count    delay total  delay average
                    0              0              0ms
SWAP            count    delay total  delay average
                    0              0              0ms
RECLAIM         count    delay total  delay average
                    0              0              0ms
THRASHING       count    delay total  delay average
                    0              0              0ms
COMPACT         count    delay total  delay average
                    0              0              0ms
WPCOPY          count    delay total  delay average
                  100         244100              0ms