Flushing the processor cache and getting processor cache info (cpucache.h)

The API is defined in the header file sysroot-*-kos/include/kos/cpucache.h from the KasperskyOS SDK.

The API lets you flush the processor cache and get information about the processor cache.

Information about API functions is provided in the table below.

Flushing the processor cache

To flush the processor cache, call the KosCpuCacheFlush() function. This function flushes the processor cache of all accessible levels. You can also clear the data cache and instructions cache corresponding to the defined virtual memory region. For example, a driver must clear the processor data cache corresponding to the memory used for DMA because the caching process may cause the contents of this memory from the driver's perspective to differ from the actual contents visible to the device.

You can also flush the processor cache by using the KnHalFlushCache() function from the hal_api.h API. You must also keep in mind that the KnHalFlushCache() function always executes a system call to flush the processor cache, while the KosCpuCacheFlush() function does this only if there is no capability to flush the processor cache without this system call.

Getting processor cache info

To get information about the processor cache, call the KosCpuCacheGetInfo() function. This information includes the maximum and minimum sizes (bytes) of cache lines and information about the cache implementation restrictions on the utilized processor architecture. This information is needed when implementing low-level mechanisms for managing the processor cache, such as in drivers. For example, when implementing these mechanisms, you may need to determine the boundaries of cache lines or find out whether you can manage the cache in user mode.

A maximum and minimize size of cache lines could be required if the computing platform might include computing cores with different cache line sizes or an external processor cache controller.

Cache implementation restrictions are divided into general restrictions for all processor architectures and specific restrictions for different processor architectures. Flags that indicate general restrictions are defined in the header file sysroot-*-kos/include/rtl/cpucache.h from the KasperskyOS SDK. Flags that indicate specific restrictions are defined in the header files sysroot-*-kos/include/rtl/<processor architecture>/cpucache.h from the KasperskyOS SDK (for example, sysroot-*-kos/include/rtl/arm64/cpucache.h).

Information about API functions

cpucache.h functions

Function

Information about the function

KosCpuCacheFlush()

Purpose

Flushes the processor cache.

Parameters

  • [in] type – value defining the cache type (data cache, instructions cache, or joint data and instructions cache). The parameter type is defined in the header file sysroot-*-kos/include/rtl/cpucache.h from the KasperskyOS SDK.
  • [in] va – pointer to the virtual memory region. The cache corresponding to this region will be flushed.
  • [in] size – size (in bytes) of the virtual memory region. The cache corresponding to this region will be flushed.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosCpuCacheGetInfo()

Purpose

Gets information about the processor cache.

Parameters

  • [out] outInfo – pointer to the structure containing information about the processor cache. The structure type is defined in the header file sysroot-*-kos/include/rtl/cpucache.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

Page top