我要评分
获取效率
正确性
完整性
易理解

kupl_mem_query

Query the hbw address corresponding to ddr.

Interface Definition

void *kupl_mem_query(void *ddr_addr);

Parameters

Table 1 Parameter definition

Parameter

Type

Description

Input/Output

ddr_addr

void *

DDR address to be queried.

Input

Return Value

  • Success: hbw address
  • Failure: null pointer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "kupl.h"
#include <cassert>

static int a = 1;

void query_and_modify(void *args)
{
    void *hbw = kupl_mem_query(&a);
    int ret = kupl_hbw_verify(hbw, sizeof(int), 0);
    *(int *)hbw = 2;
}

int main()
{
    auto queue = kupl_queue_acquire(1);
    kupl_mem_copyin(&a, sizeof(int), KUPL_MEM_IN, queue);
    auto present = kupl_mem_is_present(&a);
    assert(present == true);
    kupl_queue_item_desc_t desc {
        .field_mask = KUPL_QUEUE_ITEM_DESC_FIELD_NAME,
        .func = query_and_modify,
        .args = nullptr,
        .name = "query_and_modify",
    };
    kupl_queue_submit(queue, &desc);
    kupl_mem_copyout(&a, sizeof(int), KUPL_MEM_OUT, queue);
    kupl_queue_wait(queue);
    present = kupl_mem_is_present(&a);
    assert(present == false);
    printf("a: %d\n", a);
}

The execution result is as follows:

a: 2
  • The preceding example demonstrates the complete swap-in and swap-out process of the ddr and hbw memory. First, use kupl_mem_copyin to copy the memory from ddr to hbw. Then, use kupl_mem_is_present to check memory accessibility. Next, submit an asynchronous task to use kupl_mem_query to look up hbw address for ddr and modify the address. Finally, use kupl_mem_copyout to copy the hbw address back to ddr.