---
title: DAS接口
description: "介绍DAS智能预取算法接口。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengaccel/storage/ksal/kunpengksal_16_0027.html
sourcePath: /source/zh/kunpengaccel/storage/ksal/kunpengksal_16_0027.html
indexId: a1f96dd65550dc33e0293350b0d79276e045a34f84808ccdad0e5c8fa3e5e34361
---
# DAS接口

#### 接口描述

介绍DAS智能预取算法接口。


#### 接口格式

- int32_t Rcache_CreateDasModule(DasModuleParam *createInstanceParam);
- void Rcache_ExitDasModule(void);
- int32_t Rcache_PutDasInfo(DasKvParam *params);


#### 参数释义

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| createInstanceParam | 用户注册的回调函数结构体指针 | 需要用户注册的回调函数。 | 输入 |
| params | 用户提交IO信息结构体指针 | 用户提交IO信息至智能预取算法接口。 | 输入 |
| ret | 整型数 | 成功返回0，其他失败返回对应错误码。 | 输出 |


#### 数据结构


**表1 struct DasOPS**

| 成员名 | 类型 | 描述 |
| --- | --- | --- |
| SubmitDasPrefetch | 函数指针 | 预取IO的提交函数。 |
| logFunc | 函数指针 | DAS内部日志打印函数。 |


**表2 struct DasModuleParam**

| 成员名 | 类型 | 描述 |
| --- | --- | --- |
| ops | struct DasOPS结构体指针 | 用户注册的回调函数。 |
| logger | 指针 | 用户的日志模块对象。 |
| cacheLineSize | 整型数 | 缓存行大小。 |


**表3 struct DasKvParam**

| 成员名 | 类型 | 描述 |
| --- | --- | --- |
| offset | 整型数 | 预取IO起始位置，字节的整数倍。 |
| len | 整型数 | 预取IO长度，字节的整数倍。 |
| timeStamp | 整型数 | IO的时间戳，单位：纳秒。 |
| lunID | 整型数 | IO的逻辑单元号。 |


#### 使用依赖

ksal/das.h


#### 使用实例


1. 编写DAS测试代码。

  a. 新建“test.cpp”文件。
    1 vi test.cpp

  b. 按“i”键进入编辑模式，添加如下测试代码。
    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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include <cstdio> #include <vector> #include <ksal/das.h> std::vector<DasKvParam> prefetchInfoLists; void das_req_prefetch(DasKvParam *params){ DasKvParam prefetchInfo = {params->offset, params->len, params->timeStamp, params->lunID}; prefetchInfoLists.push_back(prefetchInfo); } void ProducerTask(const uint32_t ioNum) { bool readyToExit = false; int32_t ret = 0; uint32_t counter = 0; for (uint32_t i = 0; i < ioNum; i++){ DasKvParam params; params.offset = 4096 * i; params.len = 4096; params.timeStamp = 0 + i * 10000000; params.lunID = 1; ret = Rcache_PutDasInfo(&params); } } int main(int argc, char **argv) { DasModuleParam *dasInstanceParam = new DasModuleParam(); dasInstanceParam->cacheLineSize = 8192; dasInstanceParam->logger = nullptr; DasOPS *regOps = new DasOPS(); regOps->SubmitDasPrefetch = das_req_prefetch; regOps->logFunc = nullptr; dasInstanceParam->ops = regOps; int32_t ret = Rcache_CeateDasModule(dasInstanceParam); uint32_t ioNum = 10000; ProducerTask(ioNum); for (int i = 0; i < prefetchInfoLists.size(); ++i) { printf("prefetchInfo: lunId[%u], offset[%lu], len[%lu]\n", prefetchInfoLists[i].lunID,prefetchInfoLists[i].offset, prefetchInfoLists[i].len); } Rcache_ExitDasModule(); return 0; }

  c. 按“Esc”键退出编辑模式，输入:wq!并按“Enter”键保存退出文件。
2. 编译“test.cpp”文件，生成test可执行文件。
  1 g++ test.cpp -lpthread -ldas -o test

3. 运行test可执行文件。
  1 ./test

  执行输出如下。 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 config_dasOff: 0 config_dasMemLimit: 300 MB config_prefetchMaxLen: 16 MB create DAS module clloector success. prefetchInfo: lunId[1], offset[20480], len[65536] prefetchInfo: lunId[1], offset[86016], len[65536] prefetchInfo: lunId[1], offset[151552], len[65536] prefetchInfo: lunId[1], offset[217088], len[65536] prefetchInfo: lunId[1], offset[282624], len[65536] prefetchInfo: lunId[1], offset[348160], len[65536] prefetchInfo: lunId[1], offset[413696], len[65536] prefetchInfo: lunId[1], offset[479232], len[65536] prefetchInfo: lunId[1], offset[544768], len[65536] prefetchInfo: lunId[1], offset[610304], len[65536] prefetchInfo: lunId[1], offset[675840], len[65536] prefetchInfo: lunId[1], offset[741376], len[65536] prefetchInfo: lunId[1], offset[806912], len[73728] prefetchInfo: lunId[1], offset[880640], len[73728] prefetchInfo: lunId[1], offset[954368], len[81920] prefetchInfo: lunId[1], offset[1036288], len[81920] prefetchInfo: lunId[1], offset[1118208], len[90112] prefetchInfo: lunId[1], offset[1208320], len[90112] prefetchInfo: lunId[1], offset[1298432], len[98304] prefetchInfo: lunId[1], offset[1396736], len[98304] prefetchInfo: lunId[1], offset[1495040], len[106496] prefetchInfo: lunId[1], offset[1601536], len[106496] prefetchInfo: lunId[1], offset[1708032], len[114688] prefetchInfo: lunId[1], offset[1822720], len[114688] prefetchInfo: lunId[1], offset[1937408], len[122880] prefetchInfo: lunId[1], offset[2060288], len[122880] prefetchInfo: lunId[1], offset[2183168], len[131072] prefetchInfo: lunId[1], offset[2314240], len[131072] prefetchInfo: lunId[1], offset[2445312], len[139264] prefetchInfo: lunId[1], offset[2584576], len[139264] prefetchInfo: lunId[1], offset[2723840], len[147456] prefetchInfo: lunId[1], offset[2871296], len[147456] prefetchInfo: lunId[1], offset[3018752], len[155648] prefetchInfo: lunId[1], offset[3174400], len[155648] prefetchInfo: lunId[1], offset[3330048], len[163840] prefetchInfo: lunId[1], offset[3493888], len[163840] prefetchInfo: lunId[1], offset[3657728], len[172032] prefetchInfo: lunId[1], offset[3829760], len[172032] prefetchInfo: lunId[1], offset[4001792], len[180224] prefetchInfo: lunId[1], offset[4182016], len[180224] prefetchInfo: lunId[1], offset[4362240], len[188416] prefetchInfo: lunId[1], offset[4550656], len[360448] prefetchInfo: lunId[1], offset[4911104], len[720896] prefetchInfo: lunId[1], offset[5632000], len[1441792] prefetchInfo: lunId[1], offset[1781760], len[1048576] prefetchInfo: lunId[1], offset[2830336], len[1048576] prefetchInfo: lunId[1], offset[3878912], len[1048576] prefetchInfo: lunId[1], offset[4927488], len[1048576] prefetchInfo: lunId[1], offset[5976064], len[1048576] das mem used : 316688 Byte exit DAS module prefetcher exit DAS module collector
