Rate This Document
Findability
Accuracy
Completeness
Readability

kupl_mem_copyout

Copy memory from hbw to ddr.

Interface Definition

int kupl_mem_copyout(void *ddr_addr, size_t size, kupl_mem_copyout_flag_t flag, kupl_queue_h queue);

Parameters

Table 1 Parameter definition

Parameter

Type

Description

Input/Output

ddr_addr

void *

Address of the DDR memory to be copied.

Input

size

size_t

Size of the memory to be copied, in bytes.

Input

flag

kupl_mem_copyout_flag_t

Type of the swap-in operation, including:

KUPL_MEM_DELETE: If ddr_addr is in the present state, decrement the reference count by 1. When the reference count reaches 0, the mapping from ddr to hbw is destroyed (the state changes to non-present).

KUPL_MEM_OUT: If ddr_addr is in the present state, decrement the reference count by 1. When the reference count reaches 0, the mapping from ddr to hbw is destroyed (the state changes to non-present).

KUPL_MEM_PULL: copies the content from hbw to ddr.

KUPL_MEM_DELETE_FINALIZE: destroys the mapping.

KUPL_MEM_OUT_FINALIZE: copies the memory from hbw to ddr and destroys the mapping.

Input

queue

kupl_queue_h

Queue on which the operation is performed.

Input

Return Value

  • Success: KUPL_OK
  • Failure: KUPL_ERROR

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.