CV-Bowen opened a new pull request, #22233:
URL: https://github.com/apache/nuttx/pull/22233
## Summary
`setlogmask()` changes one global mask in the flat build, so a task that
lowers its own log level silences the SYSLOG output of every other task.
POSIX makes the mask a per-process value, and the comment of
`setlogmask()` carried this as a REVISIT. In the kernel build the mask
already lives in each process's own copy of libc, so the `setlogmask`
command changes only its own mask and exits, with no effect at all.
- `!syslog: make setlogmask() per process, add nx_setlogmask()`: the
mask of `setlogmask()` moves into the task info of the calling task
group. A new group starts with the system wide mask `g_syslog_mask`,
which moves from libc to `drivers/syslog`. The new `nx_setlogmask()`
(also a system call) sets `g_syslog_mask` and the mask of every
existing group, for callers that must change the log level of the
whole system. In the kernel build it selects the address environment
of each process to reach its task info. `vsyslog()` lets everything
pass while there is no task info yet (early boot), and
`nx_setlogmask()` skips a group whose task info an exiting task has
already freed (`task_uninit_info()` now clears `tg_info` first). The
coredump to syslog (`sched/misc/coredump.c`) now lowers the system wide
mask with `nx_setlogmask()`, so the other tasks' INFO and DEBUG
messages stay out of the dump.
- `syslog: filter kernel syslog() by the system wide mask only`: with
the first commit alone, `syslog()` in kernel code would be filtered by
the mask of whatever task the kernel runs in, so one task's
`setlogmask(LOG_UPTO(LOG_ERR))` would hide a driver's INFO messages
while it serves that task. The new `nx_syslog()` checks only
`g_syslog_mask`, and `<syslog.h>` maps `syslog()` to it in code built
with `__KERNEL__` (with `CONFIG_SYSLOG`). In the protected build this
is how master already behaves, since the kernel has its own copy of
the mask there.
The `setlogmask` command switches to `nx_setlogmask()` in
apache/nuttx-apps#A135; it must go in together with this PR.
## Impact
- **Breaking change**: in the flat and protected builds,
`setlogmask()` no longer changes the log level of other tasks. Code
that must change the log level of the whole system calls
`nx_setlogmask()` instead, as the `setlogmask` command and the
coredump code now do.
- New `nx_setlogmask()` in `include/nuttx/syslog/syslog.h`, new system
call `nx_setlogmask`, new member `ta_syslog_mask` in
`struct task_info_s`; new `nx_syslog()` in `include/syslog.h`, and
`syslog` is a macro in kernel code.
- `nx_setlogmask(LOG_NONE)` disables all output; unlike
`setlogmask()`, a zero mask is applied, not ignored.
- `vsyslog()` in kernel code still follows the mask of the current task.
- `libs/libc/syslog/syslog.h` is removed (its only content was the
`g_syslog_mask` declaration).
- No Kconfig change.
## Testing
Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205, arm: arm-none-eabi-gcc
(GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1
**Which tasks a mask change affects.** A test-only program (not in this
PR) creates a peer task `old`, then:
1. logs at INFO from itself and from `old`;
2. calls `setlogmask(LOG_UPTO(LOG_ERR))`, logs again from both, and
makes the kernel log at INFO (a test-only `syslog(LOG_INFO, "P135
kernel info\n")` in the `/dev/null` write path, triggered by writing
`P135` there);
3. calls `nx_setlogmask(LOG_UPTO(LOG_ERR))`, creates a peer task `new`,
logs from all three and from the kernel;
4. restores the mask with `nx_setlogmask()` and logs from all three and
from the kernel.
It prints `setlogmask(0)` at start, to show the mask a new process
inherits. It runs from nsh before and after `setlogmask e` / `setlogmask
d` (the command from apache/nuttx-apps#A135 on the PR side). In the
kernel build processes share no memory, so there the program only
prints the inherited mask, logs at INFO and ERR, and makes the kernel
log at INFO after `setlogmask(LOG_UPTO(LOG_ERR))`.
| | master | first commit only | this PR |
|---|---|---|---|
| step 2: `old` INFO after `setlogmask()` in another task | hidden | shown |
shown |
| step 2: kernel INFO while the calling task has `setlogmask(ERR)` (flat) |
hidden | hidden | shown |
| step 2: same, protected build | shown | | shown |
| step 3: all INFO after `nx_setlogmask(ERR)`, incl. a new task and the
kernel | n/a | hidden | hidden |
| step 4: all INFO after restoring with `nx_setlogmask()` | n/a | shown |
shown |
| kernel build: inherited mask after `setlogmask e` | `ff` (no effect) | |
`0f` |
| kernel build: kernel INFO after `setlogmask e` | shown | | hidden |
| kernel build: kernel INFO after `setlogmask(ERR)` in the program | shown |
| shown |
Configurations, each with `CONFIG_SYSTEM_SETLOGMASK=y` and the test
program:
- sim:nsh (flat): `./nuttx`
- mps2-an500:citest_protected (protected, `make`):
`qemu-system-arm -M mps2-an500 -nographic -kernel nuttx -device
loader,file=nuttx_user.elf`
- qemu-armv7a:knsh (kernel, `make`, `make export`, apps `make import`):
`qemu-system-arm -semihosting -cpu cortex-a7 -nographic -machine
virt,virtualization=off,gic-version=2 -net none -chardev stdio,id=con,mux=on
-serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx`
<details><summary>sim:nsh, this PR</summary>
```
nsh> p135logmask
P135 mask at start ff
P135 step 1 expect: self and peer(old) info shown
P135 peer(old) step 1 info
P135 self step 1 info
P135 step 2 expect: self info hidden; peer(old) info shown only if per
process
P135 peer(old) step 2 info
P135 self step 2 err
P135 kernel expect: shown if only the system mask filters the kernel
P135 kernel info
P135 step 3 expect: all info hidden (self, peer(old), peer(new))
P135 self step 3 err
P135 kernel expect: hidden
P135 step 4 expect: all info shown again (self, peer(old), peer(new))
P135 peer(old) step 4 info
P135 peer(new) step 4 info
P135 self step 4 info
P135 kernel expect: shown
P135 kernel info
nsh> setlogmask e
nsh> p135logmask
P135 mask at start 0f
P135 step 1 expect: self and peer(old) info shown
P135 step 2 expect: self info hidden; peer(old) info shown only if per
process
P135 self step 2 err
P135 kernel expect: shown if only the system mask filters the kernel
P135 step 3 expect: all info hidden (self, peer(old), peer(new))
P135 self step 3 err
P135 kernel expect: hidden
P135 step 4 expect: all info shown again (self, peer(old), peer(new))
P135 kernel expect: shown
nsh> setlogmask d
nsh> p135logmask
P135 mask at start ff
P135 step 1 expect: self and peer(old) info shown
P135 peer(old) step 1 info
P135 self step 1 info
P135 step 2 expect: self info hidden; peer(old) info shown only if per
process
P135 peer(old) step 2 info
P135 self step 2 err
P135 kernel expect: shown if only the system mask filters the kernel
P135 kernel info
P135 step 3 expect: all info hidden (self, peer(old), peer(new))
P135 self step 3 err
P135 kernel expect: hidden
P135 step 4 expect: all info shown again (self, peer(old), peer(new))
P135 peer(old) step 4 info
P135 peer(new) step 4 info
P135 self step 4 info
P135 kernel expect: shown
P135 kernel info
nsh>
```
</details>
<details><summary>sim:nsh, master</summary>
```
nsh> p135logmask
P135 mask at start ff
P135 step 1 expect: self and peer(old) info shown
P135 peer(old) step 1 info
P135 self step 1 info
P135 step 2 expect: self info hidden; peer(old) info shown only if per
process
P135 self step 2 err
P135 kernel expect: shown if only the system mask filters the kernel
P135 nx_setlogmask() not available
```
</details>
<details><summary>mps2-an500:citest_protected, this PR</summary>
```
nsh> p135logmask
P135 mask at start ff
P135 step 1 expect: self and peer(old) info shown
P135 peer(old) step 1 info
P135 self step 1 info
P135 step 2 expect: self info hidden; peer(old) info shown only if per
process
P135 peer(old) step 2 info
P135 self step 2 err
P135 kernel expect: shown if only the system mask filters the kernel
P135 kernel info
P135 step 3 expect: all info hidden (self, peer(old), peer(new))
P135 self step 3 err
P135 kernel expect: hidden
P135 step 4 expect: all info shown again (self, peer(old), peer(new))
P135 peer(new) step 4 info
P135 peer(old) step 4 info
P135 self step 4 info
P135 kernel expect: shown
P135 kernel info
nsh> setlogmask e
nsh> p135logmask
P135 mask at start 0f
P135 step 1 expect: self and peer(old) info shown
P135 step 2 expect: self info hidden; peer(old) info shown only if per
process
P135 self step 2 err
P135 kernel expect: shown if only the system mask filters the kernel
P135 step 3 expect: all info hidden (self, peer(old), peer(new))
P135 self step 3 err
P135 kernel expect: hidden
P135 step 4 expect: all info shown again (self, peer(old), peer(new))
P135 kernel expect: shown
nsh> setlogmask d
nsh> p135logmask
P135 mask at start ff
P135 step 1 expect: self and peer(old) info shown
P135 peer(old) step 1 info
P135 self step 1 info
P135 step 2 expect: self info hidden; peer(old) info shown only if per
process
P135 peer(old) step 2 info
P135 self step 2 err
P135 kernel expect: shown if only the system mask filters the kernel
P135 kernel info
P135 step 3 expect: all info hidden (self, peer(old), peer(new))
P135 self step 3 err
P135 kernel expect: hidden
P135 step 4 expect: all info shown again (self, peer(old), peer(new))
P135 peer(old) step 4 info
P135 peer(new) step 4 info
P135 self step 4 info
P135 kernel expect: shown
P135 kernel info
nsh>
```
</details>
<details><summary>qemu-armv7a:knsh, this PR</summary>
```
nsh> /system/bin/p135logmask
P135 mask at start ff
[ 0.285202] P135 self info
[ 0.285897] P135 self err
P135 kernel expect: shown if only the system mask filters the kernel
[ 0.286537] P135 kernel info
nsh> /system/bin/setlogmask e
nsh> /system/bin/p135logmask
P135 mask at start 0f
[ 0.398705] P135 self err
P135 kernel expect: shown if only the system mask filters the kernel
nsh> /system/bin/setlogmask d
nsh> /system/bin/p135logmask
P135 mask at start ff
[ 0.509747] P135 self info
[ 0.509887] P135 self err
P135 kernel expect: shown if only the system mask filters the kernel
[ 0.510401] P135 kernel info
```
</details>
<details><summary>qemu-armv7a:knsh, master</summary>
```
nsh> /system/bin/p135logmask
P135 mask at start ff
[ 0.247418] P135 self info
[ 0.248077] P135 self err
P135 kernel expect: shown if only the system mask filters the kernel
[ 0.248641] P135 kernel info
nsh> /system/bin/setlogmask e
nsh> /system/bin/p135logmask
P135 mask at start ff
[ 0.359950] P135 self info
[ 0.360117] P135 self err
P135 kernel expect: shown if only the system mask filters the kernel
[ 0.360577] P135 kernel info
nsh> /system/bin/setlogmask d
nsh> /system/bin/p135logmask
P135 mask at start ff
[ 0.474402] P135 self info
[ 0.474531] P135 self err
P135 kernel expect: shown if only the system mask filters the kernel
[ 0.475076] P135 kernel info
```
</details>
**Builds.** Each commit builds with 0 warnings with
apache/nuttx-apps#A135: sim:nsh, sim:nsh + `SYSLOG_RFC5424`, sim:nsh +
`SYSLOG_NONE`, qemu-armv8a:nsh + `COREDUMP` + `BOARD_COREDUMP_SYSLOG`,
qemu-armv8a:nsh_smp, qemu-armv7a:knsh (cmake), and
mps2-an500:citest_protected (make).
Not run: a coredump to syslog at runtime (only built).
No regression in rpmsg: sim:rpserver/rpproxy and
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping,
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC
disabled, which current master needs for nxinit to start nsh there; unrelated
to this change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]