Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: yithar7153 on September 20, 2015, 07:25:53 PM

Title: Disabling spindown
Post by: yithar7153 on September 20, 2015, 07:25:53 PM
So I'm using a Ipod Classic 6G with Tarkan's CF adapter. What I noticed was that when going from one track to the next there's a lag of a few seconds. I'm pretty sure it's due to spindown.

So what I did was I commented out the "#DEFINE HAVE_DISK_STORAGE" in the ipod6g.h file. I also commented out the line in the storage_ata-ipod6g.c that creates the idle monitor thread. I figure it's fine to not power down the CF card because it takes ~1/4 of the power of the original drive (https://www.tarkan.info/20070826/tutorials/apple-video-ipod-battery-life-compact-flash/2), and I only need a runtime of about ~10 hours max per day. I'm just wondering if there's anything I'm overlooking to disable the spindown or if there's anything wrong with getting rid of the idle monitor thread.
Title: Re: Disabling spindown
Post by: cereal_killer on September 21, 2015, 03:22:15 PM
So what I did was I commented out the "#DEFINE HAVE_DISK_STORAGE" in the ipod6g.h file. I also commented out the line in the storage_ata-ipod6g.c that creates the idle monitor thread.

Is this information of use with an iPod with SSD installed? I was wondering too, if I should change any settings, but after dreamlayers response I just use an unmodified development build.

Yeah, if you don't have problems, do not use http://gerrit.rockbox.org/r/#/c/469/1 . It will only make things slower. I guess the speed decrease is why that change never got accepted.

Don't worry about the spindown timer. Trying to force 0 may cause unwanted extra drive power cycles. After that period of inactivity, Rockbox puts the drive into a low power mode and if possible on that player cuts drive power. (The 5.5G iPod can cut power.) You're not going to save a significant amount of power shortening that because idle power usage should be low, and the drive spends very little time in that state already. You might want to prolong the timer if the drive takes a long time to become available afterwards, but you didn't mention such a problem.
Title: Re: Disabling spindown
Post by: yithar7153 on September 21, 2015, 08:16:06 PM
I'm using a CompactFlash card. If you don't have problems you probably shouldn't change anything. Looking at the code Rockbox seems to actually cut off power as the function is called ata_power_down(). My problem was that my ipod classic was taking time to get the next track and it was annoying. My guess is that once the buffer is filled rockbox calls ata_spindown() or ata_sleep() which leads to ata_power_down() being triggered earlier.

I commented out lines 1207-1210 of firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c
"create_thread(ata_thread, ata_stack,
                    sizeof(ata_stack), 0, "ATA idle monitor"
                    IF_PRIO(, PRIORITY_USER_INTERFACE)
                    IF_COP(, CPU));"

So as you can see, it's an idle monitor thread. To put it simply, threads allow programs to do a bit of multitasking. (To be honest, I'm not that great at threads but I have written a few projects dealing with them so I have a basic understanding of how they work with mutexes and race conditions, etc.) The function for the thread is called ata_thread. So let's go look at that.

"static void ata_thread(void)
{
    while (true)
    {
        mutex_lock(&ata_mutex);
        if (TIME_AFTER(current_tick, ata_last_activity_value + ata_sleep_timeout) && ata_powered)
        {
            call_storage_idle_notifys(false);
            ata_power_down();
        }
        mutex_unlock(&ata_mutex);
        sleep(HZ / 2);
    }
}"

So basic rundown of what the ata_thread function does.
Acquires the lock, which blocks any other thread from acquiring the lock until it's released.
After that, it checks to see if it's past the time the ipod was last active + the sleep timeout and if the drive is powered on
If so, then it calls ata_power_down()
It releases the lock
Then it sleeps for a certain period of time.

The ata_power_down() function is a little long, but as far as I can tell it does some writing to disk (the method depending on whether it's a CE-ATA drive, the original one that came with the ipod, or not). It does some direct operations on memory. Then it sends a boolean value of false to ide_power_enable(), which seems to set a flag to false, and then calls another function pmu_hdd_enable (pmu = power management unit), which calls a function dealing with the i2c bus which writes a 0 to a certain memory address.

So I don't understand the full extent of everything that's going on, but I get the gist that ata_power_down() is powering down the drive, and that doesn't need to be done for a CF card. If you're actually using a SSD drive, it's probably better to not change anything. Looking at the runtimes (https://www.tarkan.info/20150921/tutorials/modding/runtime-shootout-dual-sdxc-msata-sdxc-and-original-hard-drive), the mSATA is actually the worst. He does comment that several 256GB drives have runtimes approaching that of the HDD, which means the power consumption is around the same as the HDD. CF is comparable to SDXC, if you look at this thread (http://www.tarkan.info/20140215/tutorials/iflash-ipod-sd-vs-cf-power-consumption-analysis). CF pretty much has the highest runtime out of all the choices, but the least amount of space.