Skip to content
  • Jakob Kummerow's avatar
    Linux/cpuinfo.c: grow buffer size as needed for 12+ core CPUs · 7a103a45
    Jakob Kummerow authored and Arjen Hiemstra's avatar Arjen Hiemstra committed
    Summary:
    Getting CPU information starts with reading /proc/cpuinfo into a buffer; if that buffer is too small, then no information will be returned at all (updateCpuInfo() will return -1, so initCpuInfo() will return early); the consequence is that ksysguardd/ksysguard/plasmaengineexplorer won't know about "system/cores" or "cpu/system/AverageClock"; that in turn will make the "System Load Viewer" plasmoid completely dysfunctional (it won't show *any* data) because it relies on "system/cores" being available.
    
    The buffer is currently 32KiB large, which is not enough on modern hardware (e.g. 12-core/24-thread systems exceed it). This patch lowers the initial size to 8KiB to be as memory-efficient as possible on low-end systems (dual/quadcore systems shouldn't ever need to grow it), and grows the buffer size as needed to accommodate arbitrarily many CPUs (tested on a 72-thread system, where the buffer grows four times, reaching 128KiB final size).
    
    When the buffer needs to grow, its size is doubled, so the overall cost of the growth scales linearly with the file size (on average, each byte is copied to a larger buffer at most once). Also, the buffer size is remembered as long as the process runs, so the cost of the growth is only incurred once on startup (or if additional CPUs come online, which is probably rare).
    
    I've verified locally that this patch fixes the issue: the System Log Viewer plasmoid shows data as expected afterwards.
    
    BUG: 384515
    
    Reviewers: davidedmundson, ahiemstra
    
    Reviewed By: ahiemstra
    
    Subscribers: ngraham, ahiemstra, cfeck, plasma-devel
    
    Tags: #plasma
    
    Differential Revision: https://phabricator.kde.org/D27362
    7a103a45