>This seems a common problem at the scheduler and RCU layer, but not specific to
>SGX.  I originally thought cond_resched() should be able to handle this, but 
>after
>reading some history it is not the case.
>
>IIUC, cond_resched_tasks_rcu_qs() was specifically introduced to to address 
>this
>issue.  See bde6c3aa9930 ("rcu: Provide cond_resched_rcu_qs() to force 
>quiescent
>states in long loops").
>
>Could you try this solution?

Hi, Kai
The result is effective, and I will adopt this more common method you suggested 
by, submit the v2 version.

Thanks Challvy Tee for validate it as follow:
We have tested the suggested fix (replacing cond_resched() with 
cond_resched_tasks_rcu_qs()) on our production environment and can confirm it 
resolves the issue.

Test environment:
- Instance type: ecs.r9it.16xlarge (SGX-enabled cloud VM with isolated CPUs) on 
ECS
- Kernel: 6.6.102-cbp.git.772159d5f.alnx4.x86_64 (PREEMPT_DYNAMIC)

Results:
- Before fix: boot time ~50s (with rcu_tasks grace period stall)
- After fix:  boot time ~10.7s (systemd-analyze: 724ms kernel + 1.575s initrd + 
8.481s userspace = 10.782s)

```
# uname -a
Linux iZbp1cp63g07kzbp93uzrhZ 6.6.102-cbp.git.772159d5f.alnx4.x86_64 #1 SMP 
PREEMPT_DYNAMIC Mon Jun 22 03:10:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
# free -h
               total        used        free      shared  buff/cache   available
Mem:           243Gi       4.5Gi       239Gi       2.3Mi       481Mi       239Gi
Swap:             0B          0B          0B
# systemd-analyze 
Startup finished in 724ms (kernel) + 1.575s (initrd) + 8.481s (userspace) = 
10.782s 
multi-user.target reached after 3.939s in userspace.
# systemd-analyze blame | head
5.416s kdump.service
2.743s sys-devices-pci0000:00-0000:00:05.0-virtio1-net-eth0.device
2.743s sys-subsystem-net-devices-eth0.device
2.534s 
sys-devices-pci0000:00-0000:00:03.0-virtio0-virtio\x2dports-vport0p1.device
2.534s dev-virtio\x2dports-org.qemu.guest_agent.0.device
2.534s dev-vport0p1.device
2.512s sys-module-configfs.device
2.510s dev-ttyS0.device
2.510s sys-devices-pnp0-00:00-tty-ttyS0.device
2.509s sys-devices-platform-serial8250-tty-ttyS1.device
# grep -o 'sgx[^ ]*' /proc/cpuinfo | sort -u
sgx
sgx_lc

# dmesg | grep -i sgx
[    0.355547] sgx: EPC section 0x4040000000-0x7e3fffffff

# ls -la /dev/sgx*
crw-rw---- 1 root sgx  10, 125 Jun 22 11:36 /dev/sgx_enclave
crw------- 1 root root 10, 126 Jun 22 11:36 /dev/sgx_provision

Warm regards
Jun Miao

Reply via email to