How does sleep really work in the Android kernel?

I’ve been wondering about this for a while, but couldn’t find anything about it. What exactly happens after the screen turns off? Does the kernel actually suspend and halt the CPU? If so, how are notifications received while sleeping? Is there a coprocessor involved?

I’m curious. It would be great if someone could point me towards some articles or videos about this.

@android@lemmy.ml @android@lemmy.world @android@lemdro.id @android@kbin.social #android #linux #kernel #sleep #suspend

  • Lojcs@lemm.ee
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    1 year ago

    I don’t think sleeping the cpu (in the sense of traditional s3 sleep) is involved. After 5 minutes of screen off time system enters doze mode, which sleeps all apps that aren’t exempt (via the settings toggle, accessibility, persistent notification etc). System stays awake and manages waking up apps every once in a while so they can sync. Apps can also be woken up at any time by alarms or by other apps. The way instant notifications work is via Google play services staying awake, receiving firebase notifications and waking up apps based on that. In new android versions (13+ I think?) there’s also a system that lets apps wake up from sleep based on how much you interact with them

    • Felix Urbasik@ma.fellr.netOP
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      @Lojcs You think so? It must do something on the hardware level. If you install something like @postmarketos and let the deivce just sit doing nothing with its screen off, the battery doesn’t last nearly as long as with Android. There must be some trickery going on…

      • ReversalHatchery@beehaw.org
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        Earlier I’ve read that it only keeps a single CPU core as active, at least for most of the time sleeping. But take this with a grain of salt, it was long ago so I may misremembered it, and also it might have changed a lot since then, but afaik this was a technique they once used (and may still do)

  • WhoRoger@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    1 year ago

    Amateur here, can only convey what I remember from reading. In sleep mode the the cpu wakes up regularly to do things that are needed for background services and connectivity.

    Now, “regularly” may still mean hundreds of times a second between milliseconds of sleep. These wake cycles are also synchronised with other parts of the system, especially networking.

    Similarly, cpu will sleep even if the phone is awake but not very active, but will wake more frequently.