Search code examples
linux-device-driverudevblock-device

What is USEC_INITIALIZED property?


I am getting the following output for udevadm info -q property -n /dev/sda

DEVLINKS=/dev/disk/by-path/pci-0000:00:1f.2-ata-1 /dev/disk/by-id/wwn-0x5000c500a90b2880 /dev/disk/by-id/ata-ST500LM021-1KJ152_W62GX4GF
DEVNAME=/dev/sda
DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
DEVTYPE=disk
ID_ATA=1
ID_ATA_DOWNLOAD_MICROCODE=1
ID_ATA_FEATURE_SET_APM=1
ID_ATA_FEATURE_SET_APM_CURRENT_VALUE=128
ID_ATA_FEATURE_SET_APM_ENABLED=1
ID_ATA_FEATURE_SET_HPA=1
ID_ATA_FEATURE_SET_HPA_ENABLED=1
ID_ATA_FEATURE_SET_PM=1
ID_ATA_FEATURE_SET_PM_ENABLED=1
ID_ATA_FEATURE_SET_PUIS=1
ID_ATA_FEATURE_SET_PUIS_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY=1
ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=78
ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=78
ID_ATA_FEATURE_SET_SMART=1
ID_ATA_FEATURE_SET_SMART_ENABLED=1
ID_ATA_ROTATION_RATE_RPM=7200
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_ATA_SATA_SIGNAL_RATE_GEN2=1
ID_ATA_WRITE_CACHE=1
ID_ATA_WRITE_CACHE_ENABLED=1
ID_BUS=ata
ID_MODEL=ST500LM021-1KJ152
ID_MODEL_ENC=ST500LM021-1KJ152\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_PART_TABLE_TYPE=gpt
ID_PART_TABLE_UUID=f8f58152-5c2e-4c72-9b1a-8bdde0e1c8ee
ID_PATH=pci-0000:00:1f.2-ata-1
ID_PATH_TAG=pci-0000_00_1f_2-ata-1
ID_REVISION=0005SDM1
ID_SERIAL=ST500LM021-1KJ152_W62GX4GF
ID_SERIAL_SHORT=W62GX4GF
ID_TYPE=disk
ID_WWN=0x5000c500a90b2880
ID_WWN_WITH_EXTENSION=0x5000c500a90b2880
MAJOR=8
MINOR=0
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=2694098

What is the USEC_INITIALIZED property in the last line of the output.

Is it just the time between attaching the device and actual initialization of the device.

Also if it is the initialization time how will the kernel know when the device was initialized as it will be done differently for different types of devices(eg: block device, camera etc).


Solution

  • USEC_INITIALIZED is set to the value of the monotonically increasing system clock when the device is registered in udevd. This clock's guarantee is that it never goes backwards. It typically starts at 0 on boot. Here's the function, from systemd/src/libsystemd/sd-device/device-private.c:

    int device_ensure_usec_initialized(sd_device *device, sd_device *device_old) {
            usec_t when;
    
            assert(device);
    
            if (device_old && device_old->usec_initialized > 0)
                    when = device_old->usec_initialized;
            else
                    when = now(CLOCK_MONOTONIC);
    
            return device_set_usec_initialized(device, when);
    }