openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/sys-utils/lscpu.c
static int lookup_cache(char* line, struct lscpu_desc* desc)
{
    struct cpu_cache* cache;
    long long size;
    char *p, type;
    int level;

    /* Make sure line starts with "cache<nr> :" */
    if (strncmp(line, "cache", 5))
        return 0;
    for (p = line + 5; isdigit(*p); p++)
        ;
    for (; isspace(*p); p++)
        ;
    if (*p != ':')
        return 0;

    p = strstr(line, "scope=") + 6;
    /* Skip private caches, also present in sysfs */
    if (!p || strncmp(p, "Private", 7) == 0)
        return 0;
    p = strstr(line, "level=");
    if (!p || sscanf(p, "level=%d", &level) != 1)
        return 0;
    p = strstr(line, "type=") + 5;
    if (!p || !*p)
        return 0;
    type = 0;
    if (strncmp(p, "Data", 4) == 0)
        type = 'd';
    if (strncmp(p, "Instruction", 11) == 0)
        type = 'i';
    p = strstr(line, "size=");
    if (!p || sscanf(p, "size=%lld", &size) != 1)
        return 0;

    desc->necaches++;
    desc->ecaches =
        xrealloc(desc->ecaches, desc->necaches * sizeof(struct cpu_cache));
    cache = &desc->ecaches[desc->necaches - 1];
    memset(cache, 0, sizeof(*cache));
    if (type)
        xasprintf(&cache->name, "L%d%c", level, type);
    else
        xasprintf(&cache->name, "L%d", level);
    xasprintf(&cache->size, "%lldK", size);
    return 1;
}
/* Parse extra cache lines contained within /proc/cpuinfo but which are not
 * part of the cache topology information within the sysfs filesystem.
 * This is true for all shared caches on e.g. s390. When there are layers of
 * hypervisors in between it is not knows which CPUs share which caches.
 * Therefore information about shared caches is only available in
 * /proc/cpuinfo.
 * Format is:
 * "cache<nr> : level=<lvl> type=<type> scope=<scope> size=<size>
 * line_size=<lsz> associativity=<as>"
 */
Parse extra cache lines contained within /proc/cpuinfo but which are not
part of the cache topology information within the sysfs filesystem.
This is true for all shared caches on e.g. s390. When there are layers of
hypervisors in between it is not knows which CPUs share which caches.
Therefore information about shared caches is only available in
/proc/cpuinfo.
Parse extra cache lines contained within / proc / cpuinfo but which are not part of the cache topology information within the sysfs filesystem . This is true for all shared caches on e . g . s390 . When there are layers of hypervisors in between it is not knows which CPUs share which caches . Therefore information about shared caches is only available in / proc / cpuinfo .
static int lookup_cache(char* line, struct lscpu_desc* desc)
{
    struct cpu_cache* cache;
    long long size;
    char *p, type;
    int level;
    if (strncmp(line, "cache", 5))
        return 0;
    for (p = line + 5; isdigit(*p); p++)
        ;
    for (; isspace(*p); p++)
        ;
    if (*p != ':')
        return 0;
    p = strstr(line, "scope=") + 6;
    if (!p || strncmp(p, "Private", 7) == 0)
        return 0;
    p = strstr(line, "level=");
    if (!p || sscanf(p, "level=%d", &level) != 1)
        return 0;
    p = strstr(line, "type=") + 5;
    if (!p || !*p)
        return 0;
    type = 0;
    if (strncmp(p, "Data", 4) == 0)
        type = 'd';
    if (strncmp(p, "Instruction", 11) == 0)
        type = 'i';
    p = strstr(line, "size=");
    if (!p || sscanf(p, "size=%lld", &size) != 1)
        return 0;
    desc->necaches++;
    desc->ecaches =
        xrealloc(desc->ecaches, desc->necaches * sizeof(struct cpu_cache));
    cache = &desc->ecaches[desc->necaches - 1];
    memset(cache, 0, sizeof(*cache));
    if (type)
        xasprintf(&cache->name, "L%d%c", level, type);
    else
        xasprintf(&cache->name, "L%d", level);
    xasprintf(&cache->size, "%lldK", size);
    return 1;
}
static int lookup_cache ( char * line , struct lscpu_desc * desc ) { struct cpu_cache * cache ; long long size ; char * p , type ; int level ; if ( strncmp ( line , " " , 5 ) ) return 0 ; for ( p = line + 5 ; isdigit ( * p ) ; p ++ ) ; for ( ; isspace ( * p ) ; p ++ ) ; if ( * p != ' ' ) return 0 ; p = strstr ( line , " " ) + 6 ; if ( ! p || strncmp ( p , " " , 7 ) == 0 ) return 0 ; p = strstr ( line , " " ) ; if ( ! p || sscanf ( p , " " , & level ) != 1 ) return 0 ; p = strstr ( line , " " ) + 5 ; if ( ! p || ! * p ) return 0 ; type = 0 ; if ( strncmp ( p , " " , 4 ) == 0 ) type = ' ' ; if ( strncmp ( p , " " , 11 ) == 0 ) type = ' ' ; p = strstr ( line , " " ) ; if ( ! p || sscanf ( p , " " , & size ) != 1 ) return 0 ; desc -> necaches ++ ; desc -> ecaches = xrealloc ( desc -> ecaches , desc -> necaches * sizeof ( struct cpu_cache ) ) ; cache = & desc -> ecaches [ desc -> necaches - 1 ] ; memset ( cache , 0 , sizeof ( * cache ) ) ; if ( type ) xasprintf ( & cache -> name , " " , level , type ) ; else xasprintf ( & cache -> name , " " , level ) ; xasprintf ( & cache -> size , " " , size ) ; return 1 ; }
Parse extra cache lines contained within /proc/cpuinfo but which are not
 part of the cache topology information within the sysfs filesystem.
Parse extra cache lines contained within / proc / cpuinfo but which are not part of the cache topology information within the sysfs filesystem .
/* Make sure line starts with "cache<nr> :" */ /* Skip private caches, also present in sysfs */