Skip to content

Commit 07be7d8

Browse files
committed
lib: expose the number of usable memory regions through the API
The rule that turns the MRRM region count into a number of usable memory regions was implemented twice, once in the library and once in the utility, because the internal accessor has hidden visibility and the utility can only call exported symbols. Export pqos_get_num_mem_regions() so that the rule has a single implementation. It is a locked wrapper around the internal accessor, and the utility helper is reduced to reporting the failure to the user. Any application that configures region aware MBA needs this value, and deriving it from the public struct requires knowing that max_memory_regions_supported has to be limited by PQOS_MAX_MEM_REGIONS - the assumption whose absence this series is fixing. Providing the answer keeps that detail inside the library. Signed-off-by: Raghavan Kanagaraj <raghavan.kanagaraj@intel.com>
1 parent 9d9d679 commit 07be7d8

5 files changed

Lines changed: 64 additions & 20 deletions

File tree

lib/cap.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,28 @@ pqos_sysconfig_get(const struct pqos_sysconfig **sysconf)
12251225
return PQOS_RETVAL_OK;
12261226
}
12271227

1228+
int
1229+
pqos_get_num_mem_regions(unsigned *num_mem_regions)
1230+
{
1231+
int ret;
1232+
1233+
if (num_mem_regions == NULL)
1234+
return PQOS_RETVAL_PARAM;
1235+
1236+
lock_get();
1237+
1238+
ret = _pqos_check_init(1);
1239+
if (ret != PQOS_RETVAL_OK) {
1240+
lock_release();
1241+
return ret;
1242+
}
1243+
1244+
ret = mmio_get_num_mem_regions(num_mem_regions);
1245+
1246+
lock_release();
1247+
return ret;
1248+
}
1249+
12281250
void
12291251
_pqos_cap_l3cdp_change(const enum pqos_cdp_config cdp)
12301252
{

lib/pqos.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,26 @@ int pqos_cap_get(const struct pqos_cap **cap, const struct pqos_cpuinfo **cpu);
893893
*/
894894
int pqos_sysconfig_get(const struct pqos_sysconfig **sysconf);
895895

896+
/**
897+
* @brief Retrieves the number of memory regions usable on the platform
898+
*
899+
* The number of memory regions the platform implements is reported by the MRRM
900+
* ACPI table and can be larger than the PQOS_MAX_MEM_REGIONS regions the
901+
* interfaces can address. This function returns the smaller of the two, so
902+
* valid memory region numbers are 0 to *num_mem_regions - 1.
903+
*
904+
* Only supported on the MMIO interface.
905+
*
906+
* @param [out] num_mem_regions Location to store the number of memory regions
907+
*
908+
* @return Operations status
909+
* @retval PQOS_RETVAL_OK on success
910+
* @retval PQOS_RETVAL_PARAM if num_mem_regions is NULL
911+
* @retval PQOS_RETVAL_INIT if the library is not initialized
912+
* @retval PQOS_RETVAL_RESOURCE if memory region information is not available
913+
*/
914+
int pqos_get_num_mem_regions(unsigned *num_mem_regions);
915+
896916
/*
897917
* @brief Retrieves PQoS interface
898918
*

pqos/common.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,12 @@
4747
int
4848
pqos_platform_mem_regions(unsigned *num_mem_regions)
4949
{
50-
const struct pqos_sysconfig *sys = NULL;
51-
52-
if (num_mem_regions == NULL)
53-
return -1;
54-
55-
if (pqos_sysconfig_get(&sys) != PQOS_RETVAL_OK || sys == NULL ||
56-
sys->mrrm == NULL || sys->mrrm->max_memory_regions_supported == 0) {
50+
if (pqos_get_num_mem_regions(num_mem_regions) != PQOS_RETVAL_OK) {
5751
fprintf(stderr, "Memory region information is not "
5852
"available!\n");
5953
return -1;
6054
}
6155

62-
/**
63-
* MRRM reports what the platform implements, which can be more than the
64-
* PQOS_MAX_MEM_REGIONS sized arrays of the interface can carry.
65-
*/
66-
*num_mem_regions =
67-
(sys->mrrm->max_memory_regions_supported < PQOS_MAX_MEM_REGIONS)
68-
? sys->mrrm->max_memory_regions_supported
69-
: PQOS_MAX_MEM_REGIONS;
70-
7156
return 0;
7257
}
7358

pqos/common.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ int pqos_parse_mem_regions(const char *arg, int *regions, unsigned max_regions);
142142
/**
143143
* @brief Retrieves the number of memory regions supported by the platform
144144
*
145-
* The value comes from the MRRM table through the library, limited to the
146-
* PQOS_MAX_MEM_REGIONS regions the interface can address, so it is only
147-
* available after the library has been initialized. Valid memory region
148-
* numbers are 0 to *num_mem_regions - 1.
145+
* Wrapper around pqos_get_num_mem_regions() that reports the failure to the
146+
* user, so it is only usable after the library has been initialized. Valid
147+
* memory region numbers are 0 to *num_mem_regions - 1.
149148
*
150149
* @param [out] num_mem_regions number of supported memory regions
151150
*

unit-test/lib/test_cap.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,23 @@ test_pqos_fini(void **state __attribute__((unused)))
380380
assert_int_equal(ret, PQOS_RETVAL_OK);
381381
}
382382

383+
/* ======== pqos_get_num_mem_regions ======== */
384+
385+
static void
386+
test_pqos_get_num_mem_regions_before_init(void **state __attribute__((unused)))
387+
{
388+
unsigned num_mem_regions = 0;
389+
int ret;
390+
391+
ret = pqos_get_num_mem_regions(NULL);
392+
assert_int_equal(ret, PQOS_RETVAL_PARAM);
393+
394+
expect_function_call(__wrap_lock_get);
395+
expect_function_call(__wrap_lock_release);
396+
ret = pqos_get_num_mem_regions(&num_mem_regions);
397+
assert_int_equal(ret, PQOS_RETVAL_INIT);
398+
}
399+
383400
/* ======== pqos_cap_get ======== */
384401

385402
static void
@@ -578,6 +595,7 @@ main(void)
578595
cmocka_unit_test(test__pqos_get_cap_before_init),
579596
cmocka_unit_test(test__pqos_get_cpu_before_init),
580597
cmocka_unit_test(test_pqos_cap_get_before_init),
598+
cmocka_unit_test(test_pqos_get_num_mem_regions_before_init),
581599
cmocka_unit_test(test_pqos_init),
582600
cmocka_unit_test(test_pqos_cap_get_after_init),
583601
cmocka_unit_test(test__pqos_get_cap_after_init),

0 commit comments

Comments
 (0)