Commit Graph

50 Commits

Author SHA1 Message Date
David Arcari 6e942c0825 selftests/resctrl: Remove test name comparing from write_bm_pid_to_resctrl()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 0d66ddb296cc46d7b72d67cfaef0de03da092fcd
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jun 10 18:14:57 2024 +0300

    selftests/resctrl: Remove test name comparing from write_bm_pid_to_resctrl()

    write_bm_pid_to_resctrl() uses resctrl_val to check test name which is
    not a good interface generic resctrl FS functions should provide.

    Tests define mongrp when needed. Remove the test name check in
    write_bm_pid_to_resctrl() to only rely on the mongrp parameter being
    non-NULL.

    Remove write_bm_pid_to_resctrl() resctrl_val parameter and resctrl_val
    member from the struct resctrl_val_param that are not used anymore.
    Similarly, remove the test name constants that are no longer used.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:38:01 -04:00
David Arcari 7704bb8ffd selftests/resctrl: Convert ctrlgrp & mongrp to pointers
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit d14d94da0e3f1d7e598f88204cf37ee41a06f900
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jun 10 18:14:54 2024 +0300

    selftests/resctrl: Convert ctrlgrp & mongrp to pointers

    The struct resctrl_val_param has control and monitor groups as char
    arrays but they are not supposed to be mutated within resctrl_val().

    Convert the ctrlgrp and mongrp char array within resctrl_val_param to
    plain const char pointers and adjust the strlen() based checks to
    check NULL instead.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:38:00 -04:00
David Arcari 9141549aa2 selftests/resctrl: Make some strings passed to resctrlfs functions const
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 909592b5dafa3680994b1d5144b6d5781eb49ab8
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jun 10 18:14:53 2024 +0300

    selftests/resctrl: Make some strings passed to resctrlfs functions const

    Control group, monitor group and resctrl_val are not mutated and
    should not be mutated within resctrlfs.c functions.

    Mark this by using const char * for the arguments.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:38:00 -04:00
David Arcari 7015f4671a selftests/resctrl: Simplify bandwidth report type handling
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit fa1116d06ebc4673c4e8ca23d8e7ef73db544480
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jun 10 18:14:52 2024 +0300

    selftests/resctrl: Simplify bandwidth report type handling

    bw_report is only needed for selecting the correct value from the
    values IMC measured. It is a member in the resctrl_val_param struct and
    is always set to "reads". The value is then checked in resctrl_val()
    using validate_bw_report_request() that besides validating the input,
    assumes it can mutate the string which is questionable programming
    practice.

    Simplify handling bw_report:

    - Convert validate_bw_report_request() into get_bw_report_type() that
      inputs and returns const char *. Use NULL to indicate error.

    - Validate the report types inside measure_mem_bw(), not in
      resctrl_val().

    - Pass bw_report to measure_mem_bw() from ->measure() hook because
      resctrl_val() no longer needs bw_report for anything.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:38:00 -04:00
David Arcari 4221469a8b selftests/resctrl: Use correct type for pids
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 8245a70edad18e5eba479c5ea91beb590590b237
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jun 10 18:14:46 2024 +0300

    selftests/resctrl: Use correct type for pids

    A few functions receive PIDs through int arguments. PIDs variables
    should be of type pid_t, not int.

    Convert pid arguments from int to pid_t.

    Before printing PID, match the type to %d by casting to int which is
    enough for Linux (standard would allow using a longer integer type but
    generalizing for that would complicate the code unnecessarily, the
    selftest code does not need to be portable).

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:38:00 -04:00
David Arcari 2cc32dbe09 selftests/resctrl: Make "bandwidth" consistent in comments & prints
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 2704b2d117c52cd156bcdcad1eefd9c2dad1794d
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jun 10 18:14:44 2024 +0300

    selftests/resctrl: Make "bandwidth" consistent in comments & prints

    Resctrl selftests refer to "bandwidth" currently in two other forms in
    the code ("B/W" and "band width").

    Use "bandwidth" consistently everywhere. While at it, fix also one
    "over flow" -> "overflow" on a line that is touched by the change.

    Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:59 -04:00
David Arcari 73b3e11336 selftests/resctrl: Add resource_info_file_exists()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 74e76cbabd7f71f46afdf125dd4f6a54447d87e0
Author: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Date:   Fri Feb 16 09:35:41 2024 +0100

    selftests/resctrl: Add resource_info_file_exists()

    Feature checking done by resctrl_mon_feature_exists() covers features
    represented by the feature name presence inside the 'mon_features' file
    in /sys/fs/resctrl/info/L3_MON directory. There exists a different way
    to represent feature support and that is by the presence of 0 or 1 in a
    single file in the info/resource directory. In this case the filename
    represents what feature support is being indicated.

    Add a generic function to check file presence in the
    /sys/fs/resctrl/info/<RESOURCE> directory.

    Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
    Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:58 -04:00
David Arcari 442ed9b98b selftests/resctrl: Split validate_resctrl_feature_request()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 00616416488868a8b98343863e5ac078506e44e8
Author: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Date:   Fri Feb 16 09:35:28 2024 +0100

    selftests/resctrl: Split validate_resctrl_feature_request()

    validate_resctrl_feature_request() is used to test both if a resource is
    present in the info directory, and if a passed monitoring feature is
    present in the mon_features file.

    Refactor validate_resctrl_feature_request() into two smaller functions
    that each accomplish one check to give feature checking more
    granularity:
    - Resource directory presence in the /sys/fs/resctrl/info directory.
    - Feature name presence in the /sys/fs/resctrl/info/<RESOURCE>/mon_features
      file.

    Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
    Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:58 -04:00
David Arcari 76130c3c9a selftests/resctrl: Add a helper for the non-contiguous test
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit e331ac141f1df6d151d24e60ff16e93ec075509e
Author: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Date:   Fri Feb 16 09:35:15 2024 +0100

    selftests/resctrl: Add a helper for the non-contiguous test

    The CAT non-contiguous selftests have to read the file responsible for
    reporting support of non-contiguous CBMs in kernel (resctrl). Then the
    test compares if that information matches what is reported by CPUID
    output.

    Add a generic helper function to read an unsigned number from
    /sys/fs/resctrl/info/<RESOURCE>/<FILE>.

    Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
    Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:58 -04:00
David Arcari cf966241fa selftests/resctrl: Get domain id from cache id
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 345e8abe4c355bc24bab3f4a5634122e55be8665
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:05:15 2023 +0200

    selftests/resctrl: Get domain id from cache id

    Domain id is acquired differently depending on CPU. AMD tests use id
    from L3 cache, whereas CPUs from other vendors base the id on topology
    package id. In order to support L2 CAT test, this has to be
    generalized.

    The driver side code seems to get the domain ids from cache ids so the
    approach used by the AMD branch seems to match the kernel-side code. It
    will also work with L2 domain IDs as long as the cache level is
    generalized.

    Using the topology id was always fragile due to mismatch with the
    kernel-side way to acquire the domain id. It got incorrect domain id,
    e.g., when Cluster-on-Die (CoD) is enabled for CPU (but CoD is not well
    suited for resctrl in the first place so it has not been a big issue if
    tests don't work correctly with it).

    Taking all the above into account, generalize acquiring the domain id
    by taking it from the cache id and do not hard-code the cache level.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:58 -04:00
David Arcari 4f4df0e934 selftests/resctrl: Rename resource ID to domain ID
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 6874f6ed92df1e95ff815692b6bf6aa98e4c925b
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:05:14 2023 +0200

    selftests/resctrl: Rename resource ID to domain ID

    Kernel-side calls the instances of a resource domains.

    Change the resource_id naming in the selftest code to domain_id to
    match the kernel side better.

    Suggested-by: Maciej Wieczór-Retman <maciej.wieczor-retman@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:58 -04:00
David Arcari c31ba95678 selftests/resctrl: Add helper to convert L2/3 to integer
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit e73dda7ffd858a58ddeb9c53603ae14f2af8927c
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:05:13 2023 +0200

    selftests/resctrl: Add helper to convert L2/3 to integer

    "L2"/"L3" conversion to integer is embedded into get_cache_size()
    which prevents reuse.

    Create a helper for the cache string to integer conversion to make
    it reusable.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:58 -04:00
David Arcari 3db2077a8d selftests/resctrl: Pass write_schemata() resource instead of test name
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit ca1608875ae21bb40a7731b81bc0e2c95622d502
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:05:12 2023 +0200

    selftests/resctrl: Pass write_schemata() resource instead of test name

    write_schemata() takes the test name as an argument and determines the
    relevant resource based on the test name. Such mapping from name to
    resource does not really belong to resctrlfs.c that should provide
    only generic, test-independent functions.

    Pass the resource stored in the test information structure to
    write_schemata() instead of the test name. The new API is also more
    flexible as it enables to use write_schemata() for more than one
    resource within a test.

    While touching the sprintf(), move the unnecessary %c that is always
    '=' directly into the format string.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:57 -04:00
David Arcari 5ed81383de selftests/resctrl: Introduce generalized test framework
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit c603ff5bb830b8c22dae56ca3ca5ceb5c103525b
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:05:11 2023 +0200

    selftests/resctrl: Introduce generalized test framework

    Each test currently has a "run test" function in per test file and
    another resctrl_tests.c. The functions in resctrl_tests.c are almost
    identical.

    Generalize the one in resctrl_tests.c such that it can be shared
    between all of the tests. It makes adding new tests easier and removes
    the per test if () forests.

    Also add comment to CPU vendor IDs that they must be defined as bits
    for a bitmask.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:57 -04:00
David Arcari 94ebcfae24 selftests/resctrl: Restore the CPU affinity after CAT test
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 6c8cb747d071cf72c2930e09bb20ab3eabfe62ff
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:05:09 2023 +0200

    selftests/resctrl: Restore the CPU affinity after CAT test

    CAT test does not reset the CPU affinity after the benchmark.
    This is relatively harmless as is because CAT test is the last
    benchmark to run, however, more tests may be added later.

    Store the CPU affinity the first time taskset_benchmark() is run and
    add taskset_restore() which the test can call to reset the CPU mask to
    its original value.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:57 -04:00
David Arcari 04c3e1479b selftests/resctrl: Rewrite Cache Allocation Technology (CAT) test
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 205de6ddd7fff9340bd5e4b68105f28120671c6b
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:05:08 2023 +0200

    selftests/resctrl: Rewrite Cache Allocation Technology (CAT) test

    CAT test spawns two processes into two different control groups with
    exclusive schemata. Both the processes alloc a buffer from memory
    matching their allocated LLC block size and flush the entire buffer out
    of caches. Since the processes are reading through the buffer only once
    during the measurement and initially all the buffer was flushed, the
    test isn't testing CAT.

    Rewrite the CAT test to allocate a buffer sized to half of LLC. Then
    perform a sequence of tests with different LLC alloc sizes starting
    from half of the CBM bits down to 1-bit CBM. Flush the buffer before
    each test and read the buffer twice. Observe the LLC misses on the
    second read through the buffer. As the allocated LLC block gets smaller
    and smaller, the LLC misses will become larger and larger giving a
    strong signal on CAT working properly.

    The new CAT test is using only a single process because it relies on
    measured effect against another run of itself rather than another
    process adding noise. The rest of the system is set to use the CBM bits
    not used by the CAT test to keep the test isolated.

    Replace count_bits() with count_contiguous_bits() to get the first bit
    position in order to be able to calculate masks based on it.

    This change has been tested with a number of systems from different
    generations.

    Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:57 -04:00
David Arcari 3e7c914141 selftests/resctrl: Exclude shareable bits from schemata in CAT test
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit b6dfac948686799169c899557a179b84d0d1f47e
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:04:56 2023 +0200

    selftests/resctrl: Exclude shareable bits from schemata in CAT test

    CAT test doesn't take shareable bits into account, i.e., the test might
    be sharing cache with some devices (e.g., graphics).

    Introduce get_mask_no_shareable() and use it to provision an
    environment for CAT test where the allocated LLC is isolated better.
    Excluding shareable_bits may create hole(s) into the cbm_mask, thus add
    a new helper count_contiguous_bits() to find the longest contiguous set
    of CBM bits.

    create_bit_mask() is needed by an upcoming CAT test rewrite so make it
    available in resctrl.h right away.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:56 -04:00
David Arcari a602b240eb selftests/resctrl: Mark get_cache_size() cache_type const
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 60c2a6926cc94dcd8a60ab593b4092bc354061c3
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:04:54 2023 +0200

    selftests/resctrl: Mark get_cache_size() cache_type const

    get_cache_size() does not modify cache_type so it could be const.

    Mark cache_type const so that const char * can be passed to it. This
    prevents warnings once many of the test parameters are marked const.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:56 -04:00
David Arcari 4930b6e21e selftests/resctrl: Refactor get_cbm_mask() and rename to get_full_cbm()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 4b357e2a6d6c364a88d50526675fe596a30766cb
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:04:53 2023 +0200

    selftests/resctrl: Refactor get_cbm_mask() and rename to get_full_cbm()

    Callers of get_cbm_mask() are required to pass a string into which the
    capacity bitmask (CBM) is read. Neither CAT nor CMT tests need the
    bitmask as string but just convert it into an unsigned long value.

    Another limitation is that the bit mask reader can only read
    .../cbm_mask files.

    Generalize the bit mask reading function into get_bit_mask() such that
    it can be used to handle other files besides the .../cbm_mask and
    handles the unsigned long conversion within get_bit_mask() using
    fscanf(). Change get_cbm_mask() to use get_bit_mask() and rename it to
    get_full_cbm() to better indicate what the function does.

    Return error from get_full_cbm() if the bitmask is zero for some reason
    because it makes the code more robust as the selftests naturally assume
    the bitmask has some bits.

    Also mark cache_type const while at it and remove useless comments that
    are related to processing of CBM bits.

    Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:55 -04:00
David Arcari de4fff09fa selftests/resctrl: Change function comments to say < 0 on error
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 348139384ba30eccd4ce4f01fcf575b08ce81b83
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:04:50 2023 +0200

    selftests/resctrl: Change function comments to say < 0 on error

    A number function comments state the function return non-zero on
    failure but in reality they can only return 0 on success and < 0 on
    error.

    Update the comments to say < 0 on error to match the behavior.

    While at it, improve cat_val() comment to state that 0 means the test
    was run (either pass or fail).

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:55 -04:00
David Arcari c4860737f7 selftests/resctrl: Return -1 instead of errno on error
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit c90fba60f274b182f8b4df0f5a5dd23a2457f4a3
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:04:48 2023 +0200

    selftests/resctrl: Return -1 instead of errno on error

    A number of functions in the resctrl selftests return errno. It is
    problematic because errno is positive which is often counterintuitive.
    Also, every site returning errno prints the error message already with
    ksft_perror() so there is not much added value in returning the precise
    error code.

    Simply convert all places returning errno to return -1 that is typical
    userspace error code in case of failures.

    While at it, improve resctrl_val() comment to state that 0 means the
    test was run (either pass or fail).

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:55 -04:00
David Arcari 4b2a3e39e2 selftests/resctrl: Convert perror() to ksft_perror() or ksft_print_msg()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit cc8ff7f5c85c076297b18fb9f6d45ec5569d3d44
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Dec 15 17:04:47 2023 +0200

    selftests/resctrl: Convert perror() to ksft_perror() or ksft_print_msg()

    The resctrl selftest code contains a number of perror() calls. Some of
    them come with hash character and some don't. The kselftest framework
    provides ksft_perror() that is compatible with test output formatting
    so it should be used instead of adding custom hash signs.

    Some perror() calls are too far away from anything that sets error.
    For those call sites, ksft_print_msg() must be used instead.

    Convert perror() to ksft_perror() or ksft_print_msg().

    Other related changes:
    - Remove hash signs
    - Remove trailing stops & newlines from ksft_perror()
    - Add terminating newlines for converted ksft_print_msg()
    - Use consistent capitalization
    - Small fixes/tweaks to typos & grammar of the messages
    - Extract error printing out of PARENT_EXIT() to be able to
      differentiate

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:55 -04:00
David Arcari 16a9e691d5 selftests/resctrl: Move run_benchmark() to a more fitting file
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 508934b5d15ab79fd5895cc2a6063bc9d95f6a55
Author: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Date:   Tue Oct 10 09:56:12 2023 +0200

    selftests/resctrl: Move run_benchmark() to a more fitting file

    resctrlfs.c contains mostly functions that interact in some way with
    resctrl FS entries while functions inside resctrl_val.c deal with
    measurements and benchmarking.

    run_benchmark() is located in resctrlfs.c even though it's purpose
    is not interacting with the resctrl FS but to execute cache checking
    logic.

    Move run_benchmark() to resctrl_val.c just before resctrl_val() that
    makes use of run_benchmark(). Make run_benchmark() static since it's
    not used between multiple files anymore.

    Remove return comment from kernel-doc since the function is type void.

    Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
    Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:55 -04:00
David Arcari 8002431fdd selftests/resctrl: Fix schemata write error check
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 20d96b25cc4c45823fbec5406ae5ae45da6a892e
Author: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Date:   Tue Oct 10 09:56:11 2023 +0200

    selftests/resctrl: Fix schemata write error check

    Writing bitmasks to the schemata can fail when the bitmask doesn't
    adhere to constraints defined by what a particular CPU supports.
    Some example of constraints are max length or having contiguous bits.
    The driver should properly return errors when any rule concerning
    bitmask format is broken.

    Resctrl FS returns error codes from fprintf() only when fclose() is
    called. Current error checking scheme allows invalid bitmasks to be
    written into schemata file and the selftest doesn't notice because the
    fclose() error code isn't checked.

    Substitute fopen(), flose() and fprintf() with open(), close() and
    write() to avoid error code buffering between fprintf() and fclose().

    Remove newline character from the schema string after writing it to
    the schemata file so it prints correctly before function return.

    Pass the string generated with strerror() to the "reason" buffer so
    the error message is more verbose. Extend "reason" buffer so it can hold
    longer messages.

    Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
    Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:55 -04:00
David Arcari 1f57560f33 selftests/resctrl: Refactor feature check to use resource and feature name
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit d56e5da0e0f557a206bace16bbbdad00a5800e34
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Oct 2 12:48:11 2023 +0300

    selftests/resctrl: Refactor feature check to use resource and feature name

    Feature check in validate_resctrl_feature_request() takes in the test
    name string and maps that to what to check per test.

    Pass resource and feature names to validate_resctrl_feature_request()
    directly rather than deriving them from the test name inside the
    function which makes the feature check easier to extend for new test
    cases.

    Use !! in the return statement to make the boolean conversion more
    obvious even if it is not strictly necessary from correctness point of
    view (to avoid it looking like the function is returning a freed
    pointer).

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
    Cc: <stable@vger.kernel.org> # selftests/resctrl: Remove duplicate feature check from CMT test
    Cc: <stable@vger.kernel.org> # selftests/resctrl: Move _GNU_SOURCE define into Makefile
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:54 -04:00
David Arcari adf87b4681 selftests/resctrl: Don't pass test name to fill_buf
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 7f3c980c7738d0624077f926216bc7ac4cefcf60
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jul 17 16:15:03 2023 +0300

    selftests/resctrl: Don't pass test name to fill_buf

    Test name is passed to fill_buf functions so that they can loop around
    buffer only once. This is required for CAT test case.

    To loop around buffer only once, caller doesn't need to let fill_buf
    know which test case it is. Instead, pass a boolean argument 'once'
    which makes fill_buf more generic.

    As run_benchmark() no longer needs to pass the test name to
    run_fill_buf(), a few test running functions can be simplified to not
    write the test name into the default benchmark_cmd. The has_ben
    argument can also be removed now from those test running functions.

    Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:52 -04:00
David Arcari 44a246d216 selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 326baed260e2e4f2df18d42d41b261740c6b8c04
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jul 17 16:15:00 2023 +0300

    selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()

    run_fill_buf()'s malloc_and_init_memory parameter is always 1. There's
    also duplicated memory init code for malloc_and_init_memory == 0 case
    in fill_buf() which is unused.

    Remove the malloc_and_init_memory parameter and the duplicated mem init
    code.

    While at it, fix also a typo in run_fill_buf() prototype's argument.

    Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:52 -04:00
David Arcari 2449a461e9 selftests/resctrl: Express span internally in bytes
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit e24ac42889810168f7a2022b868bb4b9a9481760
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jul 17 16:14:58 2023 +0300

    selftests/resctrl: Express span internally in bytes

    MBA and MBM tests to use megabytes to represent span. CMT test uses
    bytes. The difference requires run_benchmark() to size the buffer
    differently based on the test name, which in turn requires passing the
    test name into run_benchmark().

    Convert MBA and MBM tests to use span internally in bytes like CMT test
    to remove the internal inconsistency between the tests. Remove the test
    dependent buffer sizing from run_benchmark().

    This change eliminates one of the reasons why the test name has to be
    passed around but there are still other users too so the test name
    passing cannot yet be removed.

    Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:52 -04:00
David Arcari bc6c09ce18 selftests/resctrl: Convert span to size_t
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 67a86643db2b12408430d1d627b3dc6208f06765
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jul 17 16:14:57 2023 +0300

    selftests/resctrl: Convert span to size_t

    Span is defined either as unsigned long or int.

    Consistently use size_t everywhere for span as it refers to size of the
    memory block.

    Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:52 -04:00
David Arcari 19518af15a selftests/resctrl: Refactor remount_resctrl(bool mum_resctrlfs) to mount_resctrl()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 6383851a193b76dbd3ec09b91154e2dda6c96308
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jul 17 16:14:55 2023 +0300

    selftests/resctrl: Refactor remount_resctrl(bool mum_resctrlfs) to mount_resctrl()

    Mount/umount of the resctrl FS is now paired nicely per test.

    Rename remount_resctrl(bool mum_resctrlfs) to mount_resctrl(). Make
    it unconditionally try to mount the resctrl FS and return error if
    resctrl FS was mounted already.

    While at it, group the mount/umount prototypes in the header.

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:51 -04:00
David Arcari 846269ff58 selftests/resctrl: Move resctrl FS mount/umount to higher level
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit caddc0fbe4958a84b0dcd257439e9090c8fbfb8e
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jul 17 16:14:54 2023 +0300

    selftests/resctrl: Move resctrl FS mount/umount to higher level

    A few places currently lack umounting resctrl FS on error paths:
      - cmt_resctrl_val() has multiple error paths with direct return.
      - cat_perf_miss_val() has multiple error paths with direct return.
    In addition, validate_resctrl_feature_request() is called by
    run_mbm_test() and run_mba_test(). Neither MBA nor MBM test tries to
    umount resctrl FS.

    Each and every test does require resctrl FS to be present already for
    feature check. Thus, it makes sense to just mount it on higher level in
    resctrl_tests.c and properly pair it with umount.

    Move resctrl FS (re)mount/unmount into each test function in
    resctrl_tests.c. Make feature validation to simply check that resctrl
    FS is mounted.

    As there's the final umount in main() before this change, the selftest
    should not leave resctrl FS behind after the tests even if one of the
    forementioned paths is taken (thus, no fixes tag).

    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:51 -04:00
David Arcari 54992a4897 selftests/resctrl: Unmount resctrl FS before starting the first test
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit ede13008489b36f2adcdf01e3f6435c7b24610c1
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Mon Jul 17 16:14:53 2023 +0300

    selftests/resctrl: Unmount resctrl FS before starting the first test

    Resctrl FS mount/remount/umount code is hard to track. Better approach
    is to use mount/umount pair for each test but that assumes resctrl FS
    is not mounted beforehand.

    Change umount_resctrlfs() so that it can unmount resctrl FS from any
    path, and enable further simplifications into mount/remount/umount
    logic by unmounting resctrl FS at the start if a pre-existing
    mountpoint is found.

    Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Tested-by: Babu Moger <babu.moger@amd.com>
    Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:51 -04:00
David Arcari 629d089876 selftests/resctrl: Flush stdout file buffer before executing fork()
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit a080b6e74b241dbc7e13dd378d6f6fc884579196
Author: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Date:   Thu Apr 13 16:22:56 2023 +0900

    selftests/resctrl: Flush stdout file buffer before executing fork()

    When a process has buffered output, a child process created by fork()
    will also copy buffered output. When using kselftest framework,
    the output (resctrl test result message) will be printed multiple times.

    Add fflush() to flush out the buffered output before executing fork().

    Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:50 -04:00
David Arcari ed2f91b496 selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 42e3b093eb7c8de823d15f7fa674a99ab8edf1ff
Author: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Date:   Thu Apr 13 16:22:54 2023 +0900

    selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test

    There is a comment "Set up shemata with 100% allocation on the first run"
    in function mbm_setup(), but there is an increment bug and the condition
    "num_of_runs == 0" will never be met and write_schemata() will never be
    called to set schemata to 100%. Even if write_schemata() is called in MBM
    test, since it is not supported for MBM test it does not set the schemata.
    This is currently fine because resctrl_val_parm->mum_resctrlfs is always 1
    and umount/mount will be run in each test to set the schemata to 100%.

    To support the usage when MBM test does not unmount/remount resctrl
    filesystem before the test starts, fix to call write_schemata() and
    set schemata properly when the function is called for the first time.

    Also, remove static local variable 'num_of_runs' because this is not
    needed as there is resctrl_val_param->num_of_runs which should be used
    instead like in cat_setup().

    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:50 -04:00
David Arcari 03cfd67ee0 selftests/resctrl: Change name from CBM_MASK_PATH to INFO_PATH
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit e48c32306bce38a7b2617543fe0d8d51ca49a448
Author: Fenghua Yu <fenghua.yu@intel.com>
Date:   Wed Feb 15 15:06:03 2023 +0200

    selftests/resctrl: Change name from CBM_MASK_PATH to INFO_PATH

    CBM_MASK_PATH is actually the path to resctrl/info.

    Change the macro name to correctly indicate what it represents.

    [ ij: Tweaked the changelog. ]

    Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:50 -04:00
David Arcari 62b9fe54aa selftests/resctrl: Extend CPU vendor detection
JIRA: https://issues.redhat.com/browse/RHEL-20790

commit 6220f69e72a534838cffd84dce6afd777777be03
Author: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Date:   Wed Mar 23 17:09:27 2022 +0900

    selftests/resctrl: Extend CPU vendor detection

    Currently, the resctrl_tests only has a function to detect AMD vendor.
    Since when the Intel Sub-NUMA Clustering feature is enabled,
    Intel CMT and MBM counters may not be accurate,
    the resctrl_tests also need a function to detect Intel vendor.
    And in the future, resctrl_tests will need a function to detect different
    vendors, such as Arm.

    Extend the function to detect Intel vendor as well. Also,
    this function can be easily extended to detect other vendors.

    Signed-off-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-09-16 07:37:48 -04:00
Fenghua Yu e75074781f selftests/resctrl: Change a few printed messages
Change a few printed messages to report test progress more clearly.

Add a missing "\n" at the end of one printed message.

Suggested-by: Shuah Khan <shuah@kernel.org>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-07 16:37:49 -06:00
Fenghua Yu 4e5cb354c8 selftests/resctrl: Fix unmount resctrl FS
umount_resctrlfs() directly attempts to unmount resctrl file system without
checking if resctrl FS is already mounted or not. It returns 0 on success
and on failure it prints an error message and returns an error status.
Calling umount_resctrlfs() when resctrl FS isn't mounted will return an
error status.

There could be situations where-in the caller might not know if resctrl
FS is already mounted or not and the caller might still want to unmount
resctrl FS if it's already mounted (For example during teardown).

To support above use cases, change umount_resctrlfs() such that it now
first checks if resctrl FS is already mounted or not and unmounts resctrl
FS only if it's already mounted.

unmount resctrl FS upon exit. For example, running only mba test on a
Broadwell (BDW) machine (MBA isn't supported on BDW CPU).

This happens because validate_resctrl_feature_request() would mount resctrl
FS to check if mba is enabled on the platform or not and finds that the H/W
doesn't support mba and hence will return false to run_mba_test(). This in
turn makes the main() function return without unmounting resctrl FS.

Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:58:26 -06:00
Fenghua Yu ee0415681e selftests/resctrl: Use resctrl/info for feature detection
Resctrl test suite before running any unit test (like cmt, cat, mbm and
mba) should first check if the feature is enabled (by kernel and not just
supported by H/W) on the platform or not.
validate_resctrl_feature_request() is supposed to do that. This function
intends to grep for relevant flags in /proc/cpuinfo but there are several
issues here

1. validate_resctrl_feature_request() calls fgrep() to get flags from
   /proc/cpuinfo. But, fgrep() can only return a string with maximum of 255
   characters and hence the complete cpu flags are never returned.
2. The substring search logic is also busted. If strstr() finds requested
   resctrl feature in the cpu flags, it returns pointer to the first
   occurrence. But, the logic negates the return value of strstr() and
   hence validate_resctrl_feature_request() returns false if the feature is
   present in the cpu flags and returns true if the feature is not present.
3. validate_resctrl_feature_request() checks if a resctrl feature is
   reported in /proc/cpuinfo flags or not. Having a cpu flag means that the
   H/W supports the feature, but it doesn't mean that the kernel enabled
   it. A user could selectively enable only a subset of resctrl features
   using kernel command line arguments. Hence, /proc/cpuinfo isn't a
   reliable source to check if a feature is enabled or not.

The 3rd issue being the major one and fixing it requires changing the way
validate_resctrl_feature_request() works. Since, /proc/cpuinfo isn't the
right place to check if a resctrl feature is enabled or not, a more
appropriate place is /sys/fs/resctrl/info directory. Change
validate_resctrl_feature_request() such that,

1. For cat, check if /sys/fs/resctrl/info/L3 directory is present or not
2. For mba, check if /sys/fs/resctrl/info/MB directory is present or not
3. For cmt, check if /sys/fs/resctrl/info/L3_MON directory is present and
   check if /sys/fs/resctrl/info/L3_MON/mon_features has llc_occupancy
4. For mbm, check if /sys/fs/resctrl/info/L3_MON directory is present and
   check if /sys/fs/resctrl/info/L3_MON/mon_features has
   mbm_<total/local>_bytes

Please note that only L3_CAT, L3_CMT, MBA and MBM are supported. CDP and L2
variants can be added later.

Reported-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:57:57 -06:00
Fenghua Yu a3611fbc6e selftests/resctrl: Check for resctrl mount point only if resctrl FS is supported
check_resctrlfs_support() does the following
1. Checks if the platform supports resctrl file system or not by looking
   for resctrl in /proc/filesystems
2. Calls opendir() on default resctrl file system path
   (i.e. /sys/fs/resctrl)
3. Checks if resctrl file system is mounted or not by looking at
   /proc/mounts

Steps 2 and 3 will fail if the platform does not support resctrl file
system. So, there is no need to check for them if step 1 fails.

Fix this by returning immediately if the platform does not support
resctrl file system.

Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:57:49 -06:00
Fenghua Yu ca2f4214f9 selftests/resctrl: Call kselftest APIs to log test results
Call kselftest APIs instead of using printf() to log test results
for cleaner code and better future extension.

Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:54:08 -06:00
Fenghua Yu 2f320911d9 selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.

Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.

[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
    information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html

Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:53:54 -06:00
Reinette Chatre f5f16ae4fa selftests/resctrl: Ensure sibling CPU is not same as original CPU
The resctrl tests can accept a CPU on which the tests are run and use
default of CPU #1 if it is not provided. In the CAT test a "sibling CPU"
is determined that is from the same package where another thread will be
run.

The current algorithm with which a "sibling CPU" is determined does not
take the provided/default CPU into account and when that CPU is the
first CPU in a package then the "sibling CPU" will be selected to be the
same CPU since it starts by picking the first CPU from core_siblings_list.

Fix the "sibling CPU" selection by taking the provided/default CPU into
account and ensuring a sibling that is a different CPU is selected.

Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:51:43 -06:00
Fenghua Yu 2428673638 selftests/resctrl: Clean up resctrl features check
Checking resctrl features call strcmp() to compare feature strings
(e.g. "mba", "cat" etc). The checkings are error prone and don't have
good coding style. Define the constant strings in macros and call
strncmp() to solve the potential issues.

Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:51:36 -06:00
Fenghua Yu 8236c51d85 selftests/resctrl: Fix compilation issues for global variables
Reinette reported following compilation issue on Fedora 32, gcc version
10.1.1

/usr/bin/ld: cqm_test.o:<src_dir>/cqm_test.c:22: multiple definition of
`cache_size'; cat_test.o:<src_dir>/cat_test.c:23: first defined here

The same issue is reported for long_mask, cbm_mask, count_of_bits etc
variables as well. Compiler isn't happy because these variables are
defined globally in two .c files namely cqm_test.c and cat_test.c and
the compiler during compilation finds that the variable is already
defined (multiple definition error).

Taking a closer look at the usage of these variables reveals that these
variables are used only locally in functions such as cqm_resctrl_val()
(defined in cqm_test.c) and cat_perf_miss_val() (defined in cat_test.c).
These variables are not shared between those functions. So, there is no
need for these variables to be global. Hence, fix this issue by making
them static variables.

Reported-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-04-02 13:51:24 -06:00
Babu Moger c0327e1d7c selftests/resctrl: Use cache index3 id for AMD schemata masks
AMD uses the cache l3 boundary for schemata masks. Update it accordigly.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2020-02-10 18:43:32 -07:00
Fenghua Yu 790bf585b0 selftests/resctrl: Add Cache Allocation Technology (CAT) selftest
Cache Allocation Technology (CAT) selftest allocates a portion of
last level cache and starts a benchmark to read each cache
line in this portion of cache. Measure the cache misses in perf and
the misses should be equal to the number of cache lines in this
portion of cache.

We don't use CQM to calculate cache usage because some CAT enabled
platforms don't have CQM.

Co-developed-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Co-developed-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2020-02-10 18:43:07 -07:00
Fenghua Yu 78941183d1 selftests/resctrl: Add Cache QoS Monitoring (CQM) selftest
Cache QoS Monitoring (CQM) selftest starts stressful cache benchmark
with specified size of memory to access the cache. Last Level cache
occupancy reported by CQM should be close to the size of the memory.

Co-developed-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Co-developed-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2020-02-10 18:42:57 -07:00
Fenghua Yu ecdbb911f2 selftests/resctrl: Add MBM test
MBM (Memory Bandwidth Monitoring) test is the first implemented selftest.
It starts a stressful memory bandwidth benchmark and assigns the
bandwidth pid in a resctrl monitoring group. Read and compare perf IMC
counter and MBM total bytes for the benchmark. The numbers should be
close enough to pass the test.

Default benchmark is built-in fill_buf. But users can specify their
own benchmark by option "-b".

We can add memory bandwidth monitoring for multiple processes in the
future.

Co-developed-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Co-developed-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2020-02-10 18:42:29 -07:00
Sai Praneeth Prakhya 591a6e8588 selftests/resctrl: Add basic resctrl file system operations and data
The basic resctrl file system operations and data are added for future
usage by resctrl selftest tool.

Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Co-developed-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2020-02-10 18:37:45 -07:00