設置 | 登錄 | 註冊

作者共發了3篇帖子。

Linux內核 Runtime PM

9樓 巨大八爪鱼 2025-12-5 19:12

在remove函數中,pm_runtime_disable前必須還要調用pm_runtime_dont_use_autosuspend,否則rmmod的時候有可能不會suspend設備。

static int hello_remove(struct platform_device *pdev)

{

    struct data *data = platform_get_drvdata(pdev);

    

    printk("%s\n", __func__);

    

    if (data->miscdevice_registered) {

        misc_deregister(&data->miscdevice);

        data->miscdevice_registered = false;

    }

    

    printk("---disable begin---\n");

    pm_runtime_dont_use_autosuspend(&pdev->dev);

    pm_runtime_disable(&pdev->dev);

    printk("---disable end---\n");

    return 0;

}


root@rk3308b-buildroot:/root# echo "xxx" > /dev/hello_file

[ 1852.244258] hello_open

[ 1852.244513] hello_write

[ 1852.244578] hello_release

root@rk3308b-buildroot:/root# rmmod platform_test

[ 1852.618912] hello_exit

[ 1852.619244] hello_remove

[ 1852.620159] ---disable begin---

[ 1852.620229] hello_suspend

[ 1852.620265] ---disable end---

[ 1852.620552] hello_device_release

root@rk3308b-buildroot:/root#

巨大八爪鱼 2025-12-5 19:16

suspend後再rmmod的列印:會先resume再suspend

[ 2098.009571] hello_release

root@rk3308b-buildroot:/root# echo "xxx" > /dev/hello_file

[ 2098.397681] hello_open

[ 2098.397854] hello_write

[ 2098.397914] hello_release

root@rk3308b-buildroot:/root# [ 2100.898057] hello_suspend


root@rk3308b-buildroot:/root#

root@rk3308b-buildroot:/root# rmmod platform_test

[ 2107.616929] hello_exit

[ 2107.617241] hello_resume

[ 2107.617319] hello_remove

[ 2107.617991] ---disable begin---

[ 2107.618048] hello_suspend

[ 2107.618083] ---disable end---

[ 2107.618313] hello_device_release

root@rk3308b-buildroot:/root#

巨大八爪鱼 2025-12-5 19:17
有了pm_runtime_dont_use_autosuspend函數,只要rmmod就一定會suspend。

如果之前suspend了才rmmod,那麼先resume再suspend。

如果之前沒有suspend就rmmod,那麼直接suspend。

內容轉換:

回覆帖子
內容:
用戶名: 您目前是匿名發表。
驗證碼:
看不清?換一張