Hi,
Pls help review uadk scheduler proposal
More info 【腾讯文档】uadk scheduler proposal https://docs.qq.com/doc/DRWxHeEFpVm9qVHJa
workers。","range":{"gcpBegin":409,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":409,"len":55},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":464,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":464,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":464,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{"ilvl":{"val":0},"numId":{"val":"6u41ua"}},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"scheduler驱动接管所有ops,再根据policy,分发给workers。","range":{"gcpBegin":465,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":465,"len":40},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":505,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":505,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":505,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{"ilvl":{"val":0},"numId":{"val":"6u41ua"}},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"最简单是直接转发给默认worker,当worker_num=1,忽略policy.","range":{"gcpBegin":506,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":506,"len":41},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":547,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":547,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":547,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{"ilvl":{"val":0},"numId":{"val":"6u41ua"}},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"alloc_scheduler(default_worker)传默认worker, 后续再解析环境变量,config文件或者参数传递,增加其他worker。","range":{"gcpBegin":548,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":548,"len":78},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":626,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":626,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":626,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{"ilvl":{"val":0},"numId":{"val":"6u41ua"}},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"加速器驱动不用主动注册到uadk,因为需要dlopen->probe,parse scheduler worker参数的时候再解析,类似qemu,","range":{"gcpBegin":627,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":627,"len":73},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":700,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":700,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":700,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{"ilvl":{"val":0},"numId":{"val":"6u41ua"}},"pBdr":{"bottom":{}},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":701,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":701,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":701,"len":1},"property":{"pStyle":{"val":"ablt93"},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{},"numPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"before: app -> crypto/compress api -> ops -> driver ops","range":{"gcpBegin":702,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":702,"len":56},"property":{"b":{"val":false},"i":{"val":false},"strike":{"val":false},"spacing":{"val":0},"u":{"val":"STUnderline_none"},"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":758,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":758,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":758,"len":1},"property":{"numPr":{},"snapToGrid":{"val":true},"spacing":{"line":240}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"now: app -> crypto/compress api -> ops -> scheduler ops -> policy -> driver a ops","range":{"gcpBegin":759,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":759,"len":81},"property":{"b":{"val":false},"i":{"val":false},"strike":{"val":false},"spacing":{"val":0},"u":{"val":"STUnderline_none"},"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":840,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":840,"len":1},"property":{"b":{"val":false},"i":{"val":false},"strike":{"val":false},"spacing":{"val":0},"u":{"val":"STUnderline_none"},"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":840,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"\t\t\t\t\t\t\t\t\t\t\t\t\t -> driver b ops","range":{"gcpBegin":841,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":841,"len":34},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":875,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":875,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":875,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":876,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":876,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":876,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"\b","range":{"gcpBegin":877,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":877,"len":1},"property":{"isPlaceholder":true,"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyDrawingProp","param":{"range":{"gcpBegin":877,"len":1},"property":{"anchor":{"positionV":{}},"inlineKeyword":{"extent":{"cx":5760085,"cy":2893234},"effectExtent":{"l":0,"t":0,"r":0,"b":0},"docPr":{"id":"9e5bb0c6","name":"picture","descr":"descript"},"cNvGraphicFramePr":{"graphicFrameLocks":{}},"graphic":{"graphicData":{"pic":{"nvPicPr":{"cNvPr":{"id":"1541","name":"picture","descr":"descript"},"cNvPicPr":{}},"blipFill":{"blip":{"embed":"https://docimg1.docs.qq.com/image/AgAABnWTPCRSnHZANKZD5Ivygu3e9OVX.png?w=131..." data-version="3.0.0" data-hash="f4b78a37065c67af61f432e7019a7b2f">
Background
uadk targets to support more accelerators, including cpu instruction (isa ce and isa sve) and other vendors.
Required from Fanghao
Goal
1. How to support these accelerators in the uadk framework, now uadk only support HiSilicon accelerator.
2. How to switch between these accelerators to get full performance.
Proposal
大概的想法,参考dpdk
1. scheduler也是一个驱动,采用同样的驱动接口ops
2. 必选的驱动,buildin,简化动态加载
3. 该驱动权限更高,接管所有ops,
4. scheduler驱动可带多个workers, 即真正的加速器驱动,scheduler -> workers。
5. scheduler驱动接管所有ops,再根据policy,分发给workers。
6. 最简单是直接转发给默认worker,当worker_num=1,忽略policy.
7. alloc_scheduler(default_worker)传默认worker, 后续再解析环境变量,config文件或者参数传递,增加其他worker。
8. 加速器驱动不用主动注册到uadk,因为需要dlopen->probe,parse scheduler worker参数的时候再解析,类似qemu,
before: app -> crypto/compress api -> ops -> driver ops
now: app -> crypto/compress api -> ops -> scheduler ops -> policy -> driver a ops
-> driver b ops
adapter","range":{"gcpBegin":4,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":4,"len":21},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"SettingOperation","param":{"property":{"abstractNum":{"bgss1a":{"abstractNumId":"bgss1a","lvl":{"0":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_decimal"},"lvlText":{"val":"%1."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":336,"hanging":336}},"rPr":{"rFonts":{}},"ilvl":0},"1":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerLetter"},"lvlText":{"val":"%2."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":776,"hanging":336}},"ilvl":1,"rPr":{"rFonts":{}}},"2":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerRoman"},"lvlText":{"val":"%3."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":1216,"hanging":336}},"ilvl":2,"rPr":{"rFonts":{}}},"3":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_decimal"},"lvlText":{"val":"%4."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":1656,"hanging":336}},"ilvl":3,"rPr":{"rFonts":{}}},"4":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerLetter"},"lvlText":{"val":"%5."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":2096,"hanging":336}},"ilvl":4,"rPr":{"rFonts":{}}},"5":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerRoman"},"lvlText":{"val":"%6."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":2536,"hanging":336}},"ilvl":5,"rPr":{"rFonts":{}}},"6":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_decimal"},"lvlText":{"val":"%7."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":2976,"hanging":336}},"ilvl":6,"rPr":{"rFonts":{}}},"7":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerLetter"},"lvlText":{"val":"%8."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":3416,"hanging":336}},"ilvl":7,"rPr":{"rFonts":{}}},"8":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerRoman"},"lvlText":{"val":"%9."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":3856,"hanging":336}},"ilvl":8,"rPr":{"rFonts":{}}}},"lvl_dict_op":{"opType":"Update"}}},"abstractNum_dict_op":{"opType":"Update"},"num":{"uok3bl":{"abstractNumId":{"val":"bgss1a"},"numId":"uok3bl"}},"num_dict_op":{"opType":"Update"}},"settingType":"numbering"},"propertyType":"NumberingProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":25,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":25,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":25,"len":1},"property":{"numPr":{"ilvl":{"val":0},"numId":{"val":"uok3bl"}},"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"taskPr":{},"ind":{},"jc":{"val":"STJcWml_left"}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"shengyang: request_ctx, 没有加速器会失败,用户程序忽略错误,用户程序看下。","range":{"gcpBegin":26,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":26,"len":49},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":75,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":75,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":75,"len":1},"property":{"numPr":{"ilvl":{"val":0},"numId":{"val":"uok3bl"}},"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"taskPr":{},"ind":{},"jc":{"val":"STJcWml_left"}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"wd_xxx_init->alloc_sheduler时需要缺省worker, 如何定,直接hardcode,或者wd_xxx_init解析环境?","range":{"gcpBegin":76,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":76,"len":73},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":149,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":149,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":149,"len":1},"property":{"numPr":{"ilvl":{"val":0},"numId":{"val":"uok3bl"}},"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"taskPr":{},"ind":{},"jc":{"val":"STJcWml_left"}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"alloc_scheduler woker[8] 简单用数组,还是链表之类,不限制个数","range":{"gcpBegin":150,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":150,"len":43},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":193,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":193,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":193,"len":1},"property":{"numPr":{"ilvl":{"val":0},"numId":{"val":"uok3bl"}},"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"taskPr":{},"ind":{},"jc":{"val":"STJcWml_left"}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"worker相同是否要支持。","range":{"gcpBegin":194,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":194,"len":14},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":208,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":208,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":208,"len":1},"property":{"numPr":{"ilvl":{"val":0},"numId":{"val":"uok3bl"}},"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"taskPr":{},"ind":{},"jc":{"val":"STJcWml_left"}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""}],"subStory":[],"srcGlobalPadId":"300000000$ElGxAiVojTrZ","copyStart":2292}" data-version="3.0.0" data-hash="6a0b89629c5baee33b29d681d3ded575">
TBD
1. longfang, 名字->adapter
2. shengyang: request_ctx, 没有加速器会失败,用户程序忽略错误,用户程序看下。
3. wd_xxx_init->alloc_sheduler时需要缺省worker, 如何定,直接hardcode,或者wd_xxx_init解析环境?
4. alloc_scheduler woker[8] 简单用数组,还是链表之类,不限制个数
5. worker相同是否要支持。
alloc_scheduler","range":{"gcpBegin":513,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":513,"len":30},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":543,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":543,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":543,"len":1},"property":{"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"ind":{"left":776,"leftChars_i":true},"numPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":544,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":544,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":544,"len":1},"property":{"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"ind":{"left":776},"taskPr":{},"numPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"为简化, worker 暂时只增加不减少,初始化的时候,parse条件,一步到位,","range":{"gcpBegin":545,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":545,"len":41},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":586,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":586,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":586,"len":1},"property":{"numPr":{"ilvl":{"val":0},"numId":{"val":"0tju7e"}},"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"taskPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"先不考虑动态减少worker的情况。后面看情况","range":{"gcpBegin":587,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":587,"len":23},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":610,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":610,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":610,"len":1},"property":{"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"ind":{"left":0,"firstLineChars":200},"numPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":611,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":611,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":611,"len":1},"property":{"pBdr":{},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"ind":{"left":776},"taskPr":{},"numPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"为简化,暂时不提供动态修改参数的api,诸如threshold.","range":{"gcpBegin":612,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":612,"len":32},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":644,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":644,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":644,"len":1},"property":{"numPr":{"ilvl":{"val":0},"numId":{"val":"0tju7e"}},"snapToGrid":{"val":true},"spacing":{"before":0,"after":0,"line":240},"taskPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":645,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":645,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":645,"len":1},"property":{"pStyle":{"val":"ablt93"},"pBdr":{},"snapToGrid":{"val":false},"jc":{"val":"STJcWml_left"},"taskPr":{},"rPr":{},"numPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"Example:","range":{"gcpBegin":646,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":646,"len":8},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":654,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":654,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":654,"len":1},"property":{"pStyle":{"val":"bdfjvo"},"pBdr":{},"taskPr":{},"rPr":{},"numPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"heading 3"},{"operationType":"InsertText","param":{"text":"参数传递","range":{"gcpBegin":655,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":655,"len":4},"property":{"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"SettingOperation","param":{"property":{"abstractNum":{"wvis5d":{"abstractNumId":"wvis5d","lvl":{"0":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_decimal"},"lvlText":{"val":"%1."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":336,"hanging":336}},"rPr":{},"ilvl":0},"1":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerLetter"},"lvlText":{"val":"%2."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":776,"hanging":336}},"ilvl":1},"2":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerRoman"},"lvlText":{"val":"%3."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":1216,"hanging":336}},"ilvl":2},"3":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_decimal"},"lvlText":{"val":"%4."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":1656,"hanging":336}},"ilvl":3},"4":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerLetter"},"lvlText":{"val":"%5."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":2096,"hanging":336}},"ilvl":4},"5":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerRoman"},"lvlText":{"val":"%6."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":2536,"hanging":336}},"ilvl":5},"6":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_decimal"},"lvlText":{"val":"%7."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":2976,"hanging":336}},"ilvl":6},"7":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerLetter"},"lvlText":{"val":"%8."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":3416,"hanging":336}},"ilvl":7},"8":{"start":{"val":1},"numFmt":{"val":"STNumberFormat_lowerRoman"},"lvlText":{"val":"%9."},"lvlJc":{"val":"STJcWml_left"},"pPr":{"ind":{"left":3856,"hanging":336}},"ilvl":8}},"lvl_dict_op":{"opType":"Update"}}},"abstractNum_dict_op":{"opType":"Update"},"num":{"nrbh2k":{"abstractNumId":{"val":"wvis5d"},"numId":"nrbh2k"}},"num_dict_op":{"opType":"Update"}},"settingType":"numbering"},"propertyType":"NumberingProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":659,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":659,"len":1},"property":{"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":659,"len":1},"property":{"pStyle":{"val":"ablt93"},"numPr":{"ilvl":{"val":0},"numId":{"val":"nrbh2k"}},"pBdr":{},"taskPr":{},"rPr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"... --vdev "crypto_aesni_mb0,name=aesni_mb_1" --vdev "crypto_aesni_mb1,name=aesni_mb_2" --vdev "crypto_scheduler,worker=aesni_mb_1,worker=aesni_mb_2" ...","range":{"gcpBegin":660,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":660,"len":153},"property":{"rFonts":{"ascii":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace","hAnsi":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace","eastAsia":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace","cs":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace"},"i":{"val":false},"strike":{"val":false},"color":{"val":"888888"},"sz":{"val":180},"u":{"val":"STUnderline_none"},"shd":{"val":"STShd_clear","color":"STHexColorAuto_auto","fill":"F8F8F8"},"author":"p.144115215818243108"},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":813,"len":0}},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":813,"len":1},"property":{"rFonts":{"ascii":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace","hAnsi":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace","eastAsia":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace","cs":"SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace"},"i":{"val":false},"strike":{"val":false},"color":{"val":"888888"},"sz":{"val":180},"u":{"val":"STUnderline_none"},"shd":{"val":"STShd_clear","color":"STHexColorAuto_auto","fill":"F8F8F8"},"author":"p.144115215818243108","isPlaceholder":true},"mode":1},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":813,"len":1},"property":{"numPr":{},"pBdr":{}},"mode":1},"propertyType":"ParagraphProperty","builtinStyleName":""}],"subStory":[],"srcGlobalPadId":"300000000$ElGxAiVojTrZ","copyStart":4718}" data-version="3.0.0" data-hash="03cbb5d001222496f5029b26b3fd3d59">
Advantage
no big uapi change
required one api for setting para. (env, conf, para setting)
Disadvantage / Limitation
1. 要求前提:所有驱动ops相同, comp, crypto,未来指令加速驱动?
struct wd_alg_driver {
const char *drv_name;
const char *alg_name;
~
int (*init)(void *conf, void *priv);
void (*exit)(void *priv);
int (*send)(handle_t ctx, void *drv_msg);
int (*recv)(handle_t ctx, void *drv_msg);
int (*get_usage)(void *param);
};
2. 一种算法,一个scheduler? (可以多个woker/driver)
wd_xxx_init -> alloc_scheduler
3. 为简化, worker 暂时只增加不减少,初始化的时候,parse条件,一步到位,
先不考虑动态减少worker的情况。后面看情况
4. 为简化,暂时不提供动态修改参数的api,诸如threshold.
Example:
1. 参数传递
... --vdev "crypto_aesni_mb0,name=aesni_mb_1" --vdev "crypto_aesni_mb1,name=aesni_mb_2" --vdev "crypto_scheduler,worker=aesni_mb_1,worker=aesni_mb_2" ...
This is only for demo of the adapter proposal Goals 1. support cpu instruction accelerator 2. support switch between hardware accelerator and cpu instruction
Status 1. Existing hardware accelerator are supported. 2. Add a hisi_zlib driver to simulate cpu instruction, supported by uadk_comp
Todo: 1. how to better coexist with existing wd_xxx_init. wd_xxx_init is not a must, only required for hardware resources. On platform only support cpu, wd_xxx_init can be used, but the failure should not be treated as error.
2. how to parse workers from config, or environment.
3. how to switch between hardware and cpu, ie, add policy. Now only simply add round-robin policy: adapter_roundrobin.c The plan will add at least adapter_threshold.c, ...
https://github.com/gaozhangfei/uadk/commits/adapter https://github.com/Linaro/uadk/pull/548 the pr is only for demo, not for merge.
Zhangfei Gao (4): add adapter Adding zlib drv to simulate cpu instruction driver uadk_comp: support hisi_zlib to simulate cpu instruction wd_comp: decompress complete when length are consumed
Makefile.am | 13 +- adapter/adapter.c | 245 +++++++++++++++++++++++++++++++++++ adapter/adapter_private.h | 51 ++++++++ adapter/adapter_roundrobin.c | 90 +++++++++++++ drv/hisi_comp.c | 25 ++-- drv/hisi_hpre.c | 47 ++++--- drv/hisi_sec.c | 74 ++++++----- drv/hisi_zlib.c | 167 ++++++++++++++++++++++++ include/adapter.h | 27 ++++ include/drv/wd_aead_drv.h | 16 +-- include/drv/wd_digest_drv.h | 16 +-- include/wd_alg.h | 31 ++++- include/wd_comp.h | 3 + include/wd_util.h | 8 +- libwd.map | 7 + libwd_comp.map | 2 + sample/uadk_comp.c | 58 +++++++-- wd_aead.c | 66 +++++----- wd_alg.c | 26 ++++ wd_cipher.c | 40 ++++-- wd_comp.c | 131 ++++++++++++++----- wd_dh.c | 8 +- wd_digest.c | 66 +++++++--- wd_ecc.c | 8 +- wd_rsa.c | 8 +- wd_util.c | 17 ++- 26 files changed, 1041 insertions(+), 209 deletions(-) create mode 100644 adapter/adapter.c create mode 100644 adapter/adapter_private.h create mode 100644 adapter/adapter_roundrobin.c create mode 100644 drv/hisi_zlib.c create mode 100644 include/adapter.h
only for example
1. change drv ops api, adding para driver. 2. add func wd_alg_driver_xx to replace driver->ops. 3. drv should malloc/free ctx by itself. drv.init malloc priv ctx and drv.exit free 4. all drivers are wd_alg_driver, need remove all private driver struct like wd_aead/digest_driver 5, add wd_find_drv to find drv with drv_name and alg_name, considering several drivers supporting same alg. ignoring refcont, to make it simple, since only used drivers in para are probed
Signed-off-by: Zhangfei Gao zhangfei.gao@linaro.org --- Makefile.am | 3 +- adapter/adapter.c | 245 +++++++++++++++++++++++++++++++++++ adapter/adapter_private.h | 51 ++++++++ adapter/adapter_roundrobin.c | 90 +++++++++++++ drv/hisi_comp.c | 25 ++-- drv/hisi_hpre.c | 47 ++++--- drv/hisi_sec.c | 74 ++++++----- include/adapter.h | 27 ++++ include/drv/wd_aead_drv.h | 16 +-- include/drv/wd_digest_drv.h | 16 +-- include/wd_alg.h | 31 ++++- include/wd_util.h | 8 +- libwd.map | 7 + wd_aead.c | 66 +++++----- wd_alg.c | 26 ++++ wd_cipher.c | 40 ++++-- wd_comp.c | 45 +++++-- wd_dh.c | 8 +- wd_digest.c | 66 +++++++--- wd_ecc.c | 8 +- wd_rsa.c | 8 +- wd_util.c | 17 ++- 22 files changed, 747 insertions(+), 177 deletions(-) create mode 100644 adapter/adapter.c create mode 100644 adapter/adapter_private.h create mode 100644 adapter/adapter_roundrobin.c create mode 100644 include/adapter.h
diff --git a/Makefile.am b/Makefile.am index bd7b36f..3694f7c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,7 +59,8 @@ libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \ v1/drv/hisi_zip_udrv.c v1/drv/hisi_zip_udrv.h \ v1/drv/hisi_hpre_udrv.c v1/drv/hisi_hpre_udrv.h \ v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h \ - v1/drv/hisi_rng_udrv.c v1/drv/hisi_rng_udrv.h + v1/drv/hisi_rng_udrv.c v1/drv/hisi_rng_udrv.h \ + adapter/adapter.c adapter/adapter_roundrobin.c
libwd_comp_la_SOURCES=wd_comp.c wd_comp.h wd_comp_drv.h wd_util.c wd_util.h \ wd_sched.c wd_sched.h wd.c wd.h wd_zlibwrapper.c wd_zlibwrapper.h diff --git a/adapter/adapter.c b/adapter/adapter.c new file mode 100644 index 0000000..b42384c --- /dev/null +++ b/adapter/adapter.c @@ -0,0 +1,245 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright 2023-2024 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2023-2024 Linaro ltd. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <dlfcn.h> + +#include "adapter_private.h" +#include "wd.h" + +int uadk_adapter_attach_worker(struct wd_alg_driver *adapter, + struct wd_alg_driver *drv, void *dlhandle) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + struct uadk_adapter_worker *worker; + int idx = ctx->workers_nb; + + if (idx >= UADK_MAX_NB_WORKERS) { + fprintf(stderr, "%s too many workers\n", __func__); + return -EINVAL; + } + + worker = &ctx->workers[idx]; + worker->driver = drv; + worker->dlhandle = dlhandle; + ctx->workers_nb++; + + return 0; +} + +/* todo */ +int uadk_adapter_parse(struct wd_alg_driver *adapter, char *lib_path, + char *drv_name, char *alg_name) +{ + struct wd_alg_driver *drv; + void *dlhandle = NULL; + int ret; + + if (lib_path) { + dlhandle = dlopen(lib_path, RTLD_NOW); + if (!dlhandle) { + fprintf(stderr, "%s failed to dlopen %s\n", __func__, dlerror()); + return -EINVAL; + } + } + + drv = wd_find_drv(drv_name, alg_name); + if (!drv) { + fprintf(stderr, "%s failed to find driver\n", __func__); + ret = -EINVAL; + goto fail; + } + + ret = uadk_adapter_attach_worker(adapter, drv, dlhandle); + if (ret) + goto fail; + + // parse cmdline and return + + // parse config + + // parse env + + // attach workers + + return 0; +fail: + if (dlhandle) + dlclose(dlhandle); + return ret; +} + +static int uadk_adapter_load_user_adapter(struct wd_alg_driver *adapter, + struct uadk_user_adapter *user_adapter) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + int ret; + + /* load scheduler instance operations functions */ + ctx->ops.init = user_adapter->ops->init; + ctx->ops.exit = user_adapter->ops->exit; + ctx->ops.send = user_adapter->ops->send; + ctx->ops.recv = user_adapter->ops->recv; + + if (ctx->priv) { + free(ctx->priv); + ctx->priv = NULL; + } + + if (ctx->ops.init) { + ret = ctx->ops.init(adapter); + if (ret) + return ret; + } + + ctx->mode = user_adapter->mode; + + return 0; +} + +int uadk_adapter_set_mode(struct wd_alg_driver *adapter, enum uadk_adapter_mode mode) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + int ret; + + if (mode == ctx->mode) + return 0; + + switch (mode) { + case UADK_ADAPT_MODE_ROUNDROBIN: + ret = uadk_adapter_load_user_adapter(adapter, uadk_user_adapter_roundrobin); + if (ret) + return ret; + + break; + + default: + fprintf(stderr, "Not yet supported"); + return -ENOTSUP; + } + + return 0; +} + +static int uadk_adapter_init(struct wd_alg_driver *adapter, void *conf) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + int ret, i; + + for (i = 0; i < ctx->workers_nb; i++) { + struct uadk_adapter_worker *worker = &ctx->workers[i]; + + if (worker->inited) + continue; + + ret = wd_alg_driver_init(worker->driver, conf); + if (ret) + continue; + worker->inited = true; + } + + return 0; +} + +static void uadk_adapter_exit(struct wd_alg_driver *adapter) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + int i; + + for (i = 0; i < ctx->workers_nb; i++) { + struct uadk_adapter_worker *worker = &ctx->workers[i]; + + if (!worker->inited) + continue; + + wd_alg_driver_exit(worker->driver); + worker->inited = false; + + if (worker->dlhandle) { + dlclose(worker->dlhandle); + worker->dlhandle = NULL; + } + } + + if (ctx->ops.exit) + ctx->ops.exit(adapter); +} + +static int uadk_adapter_send(struct wd_alg_driver *adapter, handle_t handle, void *msg) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + + if (unlikely(ctx->workers_nb == 0)) { + fprintf(stderr, "%s failed since no worker\n", __func__); + return -EINVAL; + } + + /* Just forward if only one worker */ + if (ctx->workers_nb == 1) + return wd_alg_driver_send(ctx->workers[0].driver, handle, msg); + + /* dispatch according to policy */ + if (ctx->ops.send) + return ctx->ops.send(adapter, handle, msg); + + return -EINVAL; +} + +static int uadk_adapter_recv(struct wd_alg_driver *adapter, handle_t handle, void *msg) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + + if (unlikely(ctx->workers_nb == 0)) { + fprintf(stderr, "%s failed since no worker\n", __func__); + return -EINVAL; + } + + /* Just forward if only one worker */ + if (ctx->workers_nb == 1) + return wd_alg_driver_recv(ctx->workers[0].driver, handle, msg); + + /* dispatch according to policy */ + if (ctx->ops.recv) + return ctx->ops.recv(adapter, handle, msg); + + return -EINVAL; +} + +struct wd_alg_driver *uadk_adapter_alloc(void) +{ + struct wd_alg_driver *adapter = malloc(sizeof(*adapter)); + + if (adapter == NULL) + return NULL; + + adapter->priv = malloc(sizeof(struct uadk_adapter_ctx)); + if (adapter->priv == NULL) { + free(adapter); + return NULL; + } + memset(adapter->priv, 0, sizeof(struct uadk_adapter_ctx)); + + adapter->init = uadk_adapter_init; + adapter->exit = uadk_adapter_exit; + adapter->send = uadk_adapter_send; + adapter->recv = uadk_adapter_recv; + + // parse env + // uadk_adapter_set_mode(adapter, mode); + + return adapter; +} + +void uadk_adapter_free(struct wd_alg_driver *adapter) +{ + if (adapter) + free(adapter->priv); + + free(adapter); +} + + diff --git a/adapter/adapter_private.h b/adapter/adapter_private.h new file mode 100644 index 0000000..c2d3112 --- /dev/null +++ b/adapter/adapter_private.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright 2023-2024 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2023-2024 Linaro ltd. + */ + +#include "adapter.h" + +/* Maximum number of bonded drv per adapter */ +#ifndef UADK_MAX_NB_WORKERS +#define UADK_MAX_NB_WORKERS (8) +#endif + +struct uadk_adapter_ops { + // worker_attach; + // worker_detach; + + // scheduler_start; + // scheduler_stop; + int (*init)(struct wd_alg_driver *drv); + void (*exit)(struct wd_alg_driver *drv); + int (*send)(struct wd_alg_driver *drv, handle_t handle, void *drv_msg); + int (*recv)(struct wd_alg_driver *drv, handle_t handle, void *drv_msg); +}; + +struct uadk_user_adapter { + const char *name; /* adapter name */ + const char *description; /* adapter description */ + enum uadk_adapter_mode mode; /* adapter mode */ + struct uadk_adapter_ops *ops; /* adapter operation */ +}; + +struct uadk_adapter_worker { + struct wd_alg_driver *driver; + /* handle of shared library */ + void *dlhandle; + bool inited; +}; + +struct uadk_adapter_ctx { + /* priviate ctx */ + void *priv; + /* worker number */ + unsigned int workers_nb; + enum uadk_adapter_mode mode; + /* workers attached to the adapter */ + struct uadk_adapter_worker workers[UADK_MAX_NB_WORKERS]; + struct uadk_adapter_ops ops; +}; + +extern struct uadk_user_adapter *uadk_user_adapter_roundrobin; diff --git a/adapter/adapter_roundrobin.c b/adapter/adapter_roundrobin.c new file mode 100644 index 0000000..6f78cff --- /dev/null +++ b/adapter/adapter_roundrobin.c @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright 2023-2024 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2023-2024 Linaro ltd. + */ + +#include <stdlib.h> +#include "adapter_private.h" + +struct rr_adapter_ctx { + unsigned int send_idx; + unsigned int recv_idx; +}; + +static int uadk_adapter_rr_init(struct wd_alg_driver *adapter) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + struct rr_adapter_ctx *priv; + + /* init may reenter, free and re-allocate */ + if (ctx->priv) + free(ctx->priv); + + priv = malloc(sizeof(*priv)); + if (!priv) + return -ENOMEM; + + memset(priv, 0, sizeof(*priv)); + ctx->priv = priv; + + return 0; +} + +static void uadk_adapter_rr_exit(struct wd_alg_driver *adapter) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + + free(ctx->priv); +} + +/* fixme, how to ensure send and recv are matched in async mode */ +static int uadk_adapter_rr_send(struct wd_alg_driver *adapter, handle_t handle, void *drv_msg) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + struct rr_adapter_ctx *priv = (struct rr_adapter_ctx *)ctx->priv; + struct uadk_adapter_worker *worker = &ctx->workers[priv->send_idx]; + int ret; + + ret = worker->driver->send(worker->driver, handle, drv_msg); + if (ret) + return ret; + + priv->send_idx++; + priv->send_idx %= ctx->workers_nb; + + return 0; +} + +static int uadk_adapter_rr_recv(struct wd_alg_driver *adapter, handle_t handle, void *drv_msg) +{ + struct uadk_adapter_ctx *ctx = (struct uadk_adapter_ctx *)adapter->priv; + struct rr_adapter_ctx *priv = (struct rr_adapter_ctx *)ctx->priv; + struct uadk_adapter_worker *worker = &ctx->workers[priv->recv_idx]; + int ret; + + ret = worker->driver->recv(worker->driver, handle, drv_msg); + if (ret) + return ret; + + priv->recv_idx++; + priv->recv_idx %= ctx->workers_nb; + + return 0; +} + +static struct uadk_adapter_ops adapter_rr_ops = { + uadk_adapter_rr_init, + uadk_adapter_rr_exit, + uadk_adapter_rr_send, + uadk_adapter_rr_recv, +}; + +static struct uadk_user_adapter rr_adapter = { + .name = "roundrobin-adapter", + .description = "adapter which will round robin across workers", + .mode = UADK_ADAPT_MODE_ROUNDROBIN, + .ops = &adapter_rr_ops +}; + +struct uadk_user_adapter *uadk_user_adapter_roundrobin = &rr_adapter; diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 01e2ad8..76903a9 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -771,21 +771,26 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp) } }
-static int hisi_zip_init(void *conf, void *priv) +static int hisi_zip_init(struct wd_alg_driver *drv, void *conf) { struct wd_ctx_config_internal *config = conf; - struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv; + struct hisi_zip_ctx *priv; struct hisi_qm_priv qm_priv; handle_t h_qp = 0; handle_t h_ctx; int i;
+ priv = malloc(sizeof(struct hisi_zip_ctx)); + if (!priv) + return -WD_EINVAL; + if (!config->ctx_num) { WD_ERR("invalid: zip init config ctx num is 0!\n"); + free(priv); return -WD_EINVAL; }
- memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal)); + memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); /* allocate qp for each context */ for (i = 0; i < config->ctx_num; i++) { h_ctx = config->ctxs[i].ctx; @@ -802,6 +807,7 @@ static int hisi_zip_init(void *conf, void *priv) }
hisi_zip_sqe_ops_adapt(h_qp); + drv->priv = priv;
return 0; out: @@ -809,13 +815,14 @@ out: h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); hisi_qm_free_qp(h_qp); } + free(priv); return -WD_EINVAL; }
-static void hisi_zip_exit(void *priv) +static void hisi_zip_exit(struct wd_alg_driver *drv) { - struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv; - struct wd_ctx_config_internal *config = &zip_ctx->config; + struct hisi_zip_ctx *priv = (struct hisi_zip_ctx *)drv->priv; + struct wd_ctx_config_internal *config = &priv->config; handle_t h_qp; int i;
@@ -823,6 +830,8 @@ static void hisi_zip_exit(void *priv) h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); hisi_qm_free_qp(h_qp); } + + free(priv); }
static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg, @@ -877,7 +886,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg, return 0; }
-static int hisi_zip_comp_send(handle_t ctx, void *comp_msg) +static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg) { struct hisi_qp *qp = wd_ctx_get_priv(ctx); struct wd_comp_msg *msg = comp_msg; @@ -1040,7 +1049,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe, return 0; }
-static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg) +static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg) { struct hisi_qp *qp = wd_ctx_get_priv(ctx); struct wd_comp_msg *recv_msg = comp_msg; diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 4d21788..67fae63 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -496,50 +496,62 @@ out: return -WD_EINVAL; }
-static int hpre_rsa_dh_init(void *conf, void *priv) +static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf) { struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf; - struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv; struct hisi_qm_priv qm_priv; int ret;
+ drv->priv = malloc(sizeof(struct hisi_hpre_ctx)); + if (!drv->priv) + return -WD_EINVAL; + if (!config->ctx_num) { WD_ERR("invalid: hpre rsa/dh init config ctx num is 0!\n"); + free(drv->priv); return -WD_EINVAL; }
qm_priv.op_type = HPRE_HW_V2_ALG_TYPE; - ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv); - if (ret) + ret = hpre_init_qm_priv(config, drv->priv, &qm_priv); + if (ret) { + free(drv->priv); return ret; + }
return 0; }
-static int hpre_ecc_init(void *conf, void *priv) +static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf) { struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf; - struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv; struct hisi_qm_priv qm_priv; int ret;
+ drv->priv = malloc(sizeof(struct hisi_hpre_ctx)); + if (!drv->priv) + return -WD_EINVAL; + if (!config->ctx_num) { WD_ERR("invalid: hpre ecc init config ctx num is 0!\n"); + free(drv->priv); return -WD_EINVAL; }
qm_priv.op_type = HPRE_HW_V2_ALG_TYPE; - ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv); - if (ret) + ret = hpre_init_qm_priv(config, drv->priv, &qm_priv); + if (ret) { + free(drv->priv); return ret; + }
return 0; }
-static void hpre_exit(void *priv) +static void hpre_exit(struct wd_alg_driver *drv) { - struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv; - struct wd_ctx_config_internal *config = &hpre_ctx->config; + struct hisi_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv; + struct wd_ctx_config_internal *config = &priv->config; handle_t h_qp; int i;
@@ -547,9 +559,10 @@ static void hpre_exit(void *priv) h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); hisi_qm_free_qp(h_qp); } + free(priv); }
-static int rsa_send(handle_t ctx, void *rsa_msg) +static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_rsa_msg *msg = rsa_msg; @@ -605,7 +618,7 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg, } }
-static int rsa_recv(handle_t ctx, void *rsa_msg) +static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -703,7 +716,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg, return WD_SUCCESS; }
-static int dh_send(handle_t ctx, void *dh_msg) +static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_dh_msg *msg = dh_msg; @@ -748,7 +761,7 @@ static int dh_send(handle_t ctx, void *dh_msg) return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt); }
-static int dh_recv(handle_t ctx, void *dh_msg) +static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -1839,7 +1852,7 @@ free_dst: return ret; }
-static int ecc_send(handle_t ctx, void *ecc_msg) +static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_ecc_msg *msg = ecc_msg; @@ -2411,7 +2424,7 @@ fail: return ret; }
-static int ecc_recv(handle_t ctx, void *ecc_msg) +static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_ecc_msg *msg = ecc_msg; diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 0527bff..1dcb9af 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -517,8 +517,8 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = { SEC_HMAC_SHA512_MAC_LEN, SEC_HMAC_SHA512_224_MAC_LEN, SEC_HMAC_SHA512_256_MAC_LEN };
-int hisi_sec_init(void *conf, void *priv); -void hisi_sec_exit(void *priv); +int hisi_sec_init(struct wd_alg_driver *drv, void *conf); +void hisi_sec_exit(struct wd_alg_driver *drv);
static int hisi_sec_get_usage(void *param) { @@ -1048,7 +1048,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe) return 0; }
-int hisi_sec_cipher_send(handle_t ctx, void *cipher_msg) +int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_cipher_msg *msg = cipher_msg; @@ -1093,7 +1093,7 @@ int hisi_sec_cipher_send(handle_t ctx, void *cipher_msg) return 0; }
-int hisi_sec_cipher_recv(handle_t ctx, void *cipher_msg) +int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_cipher_msg *recv_msg = cipher_msg; @@ -1245,7 +1245,7 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe) return 0; }
-int hisi_sec_cipher_send_v3(handle_t ctx, void *cipher_msg) +int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_cipher_msg *msg = cipher_msg; @@ -1335,7 +1335,7 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "cipher"); }
-int hisi_sec_cipher_recv_v3(handle_t ctx, void *cipher_msg) +int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_cipher_msg *recv_msg = cipher_msg; @@ -1606,7 +1606,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) return 0; }
-int hisi_sec_digest_send(handle_t ctx, void *digest_msg) +int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_digest_msg *msg = digest_msg; @@ -1673,7 +1673,7 @@ put_sgl: return ret; }
-int hisi_sec_digest_recv(handle_t ctx, void *digest_msg) +int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_digest_msg *recv_msg = digest_msg; @@ -1698,10 +1698,10 @@ int hisi_sec_digest_recv(handle_t ctx, void *digest_msg) return 0; }
-static struct wd_digest_driver hisi_digest_driver = { +static struct wd_alg_driver hisi_digest_driver = { .drv_name = "hisi_sec2", .alg_name = "digest", - .drv_ctx_size = sizeof(struct hisi_sec_ctx), + // .drv_ctx_size = sizeof(struct hisi_sec_ctx), .init = hisi_sec_init, .exit = hisi_sec_exit, }; @@ -1860,7 +1860,7 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe, sqe->bd_param |= (__u16)(de | scene); }
-int hisi_sec_digest_send_v3(handle_t ctx, void *digest_msg) +int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_digest_msg *msg = digest_msg; @@ -1958,7 +1958,7 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "digest"); }
-int hisi_sec_digest_recv_v3(handle_t ctx, void *digest_msg) +int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_digest_msg *recv_msg = digest_msg; @@ -2225,7 +2225,7 @@ static int fill_aead_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe) return 0; }
-int hisi_sec_aead_send(handle_t ctx, void *aead_msg) +int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_aead_msg *msg = aead_msg; @@ -2318,7 +2318,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, dump_sec_msg(temp_msg, "aead"); }
-int hisi_sec_aead_recv(handle_t ctx, void *aead_msg) +int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_aead_msg *recv_msg = aead_msg; @@ -2343,10 +2343,10 @@ int hisi_sec_aead_recv(handle_t ctx, void *aead_msg) return 0; }
-static struct wd_aead_driver hisi_aead_driver = { +static struct wd_alg_driver hisi_aead_driver = { .drv_name = "hisi_sec2", .alg_name = "aead", - .drv_ctx_size = sizeof(struct hisi_sec_ctx), +// .drv_ctx_size = sizeof(struct hisi_sec_ctx), .init = hisi_sec_init, .exit = hisi_sec_exit, }; @@ -2500,7 +2500,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe) return 0; }
-int hisi_sec_aead_send_v3(handle_t ctx, void *aead_msg) +int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_aead_msg *msg = aead_msg; @@ -2587,7 +2587,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "aead"); }
-int hisi_sec_aead_recv_v3(handle_t ctx, void *aead_msg) +int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_aead_msg *recv_msg = aead_msg; @@ -2625,11 +2625,11 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp) cipher_alg_driver[i].recv = hisi_sec_cipher_recv; }
- hisi_digest_driver.digest_send = hisi_sec_digest_send; - hisi_digest_driver.digest_recv = hisi_sec_digest_recv; + hisi_digest_driver.send = hisi_sec_digest_send; + hisi_digest_driver.recv = hisi_sec_digest_recv;
- hisi_aead_driver.aead_send = hisi_sec_aead_send; - hisi_aead_driver.aead_recv = hisi_sec_aead_recv; + hisi_aead_driver.send = hisi_sec_aead_send; + hisi_aead_driver.recv = hisi_sec_aead_recv; } else { WD_INFO("hisi sec init HIP09!\n"); alg_num = ARRAY_SIZE(cipher_alg_driver); @@ -2638,25 +2638,30 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp) cipher_alg_driver[i].recv = hisi_sec_cipher_recv_v3; }
- hisi_digest_driver.digest_send = hisi_sec_digest_send_v3; - hisi_digest_driver.digest_recv = hisi_sec_digest_recv_v3; + hisi_digest_driver.send = hisi_sec_digest_send_v3; + hisi_digest_driver.recv = hisi_sec_digest_recv_v3;
- hisi_aead_driver.aead_send = hisi_sec_aead_send_v3; - hisi_aead_driver.aead_recv = hisi_sec_aead_recv_v3; + hisi_aead_driver.send = hisi_sec_aead_send_v3; + hisi_aead_driver.recv = hisi_sec_aead_recv_v3; } }
-int hisi_sec_init(void *conf, void *priv) +int hisi_sec_init(struct wd_alg_driver *drv, void *conf) { struct wd_ctx_config_internal *config = conf; - struct hisi_sec_ctx *sec_ctx = priv; struct hisi_qm_priv qm_priv; + struct hisi_sec_ctx *priv; handle_t h_qp = 0; handle_t h_ctx; int i, j;
+ priv = malloc(sizeof(struct hisi_sec_ctx)); + if (!priv) + return -WD_EINVAL; + if (!config->ctx_num) { WD_ERR("invalid: sec init config ctx num is 0!\n"); + free(priv); return -WD_EINVAL; }
@@ -2675,8 +2680,9 @@ int hisi_sec_init(void *conf, void *priv) if (!h_qp) goto out; } - memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal)); + memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); hisi_sec_driver_adapter((struct hisi_qp *)h_qp); + drv->priv = priv;
return 0;
@@ -2685,26 +2691,28 @@ out: h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx); hisi_qm_free_qp(h_qp); } + free(priv); return -WD_EINVAL; }
-void hisi_sec_exit(void *priv) +void hisi_sec_exit(struct wd_alg_driver *drv) { - struct hisi_sec_ctx *sec_ctx = priv; + struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv; struct wd_ctx_config_internal *config; handle_t h_qp; int i;
- if (!sec_ctx) { + if (!priv) { WD_ERR("hisi sec exit input parameter is err!\n"); return; }
- config = &sec_ctx->config; + config = &priv->config; for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); hisi_qm_free_qp(h_qp); } + free(priv); }
static void __attribute__((constructor)) hisi_sec2_probe(void) diff --git a/include/adapter.h b/include/adapter.h new file mode 100644 index 0000000..ffb3f12 --- /dev/null +++ b/include/adapter.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright 2023-2024 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2023-2024 Linaro ltd. + */ + +#ifndef __ADAPTER_H +#define __ADAPTER_H + +#include "wd_alg.h" + +enum uadk_adapter_mode { + UADK_ADAPT_MODE_NONE, // no mode + UADK_ADAPT_MODE_ROUNDROBIN, // roundrobin + UADK_ADAPT_MODE_THRESHOLD, // > threshold, accelerator, + // < threshold, cpu + UADK_ADAPT_MODE_FAILOVER, // fail to enqueue (full or fail), switch to backup +}; + +struct wd_alg_driver *uadk_adapter_alloc(void); +void uadk_adapter_free(struct wd_alg_driver *adapter); +int uadk_adapter_set_mode(struct wd_alg_driver *adapter, enum uadk_adapter_mode mode); +int uadk_adapter_attach_worker(struct wd_alg_driver *adapter, + struct wd_alg_driver *drv, void *dlhandle); +int uadk_adapter_parse(struct wd_alg_driver *adapter, char *lib_path, + char *drv_name, char *alg_name); +#endif diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h index 8446238..495d31a 100644 --- a/include/drv/wd_aead_drv.h +++ b/include/drv/wd_aead_drv.h @@ -63,23 +63,13 @@ struct wd_aead_msg { __u8 *mac; };
-struct wd_aead_driver { - const char *drv_name; - const char *alg_name; - __u32 drv_ctx_size; - int (*init)(void *conf, void *priv); - void (*exit)(void *priv); - int (*aead_send)(handle_t ctx, void *aead_msg); - int (*aead_recv)(handle_t ctx, void *aead_msg); -}; - -void wd_aead_set_driver(struct wd_aead_driver *drv); -struct wd_aead_driver *wd_aead_get_driver(void); +void wd_aead_set_driver(struct wd_alg_driver *drv); +struct wd_alg_driver *wd_aead_get_driver(void); struct wd_aead_msg *wd_aead_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV #define WD_AEAD_SET_DRIVER(drv) \ -struct wd_aead_driver *wd_aead_get_driver(void) \ +struct wd_alg_driver *wd_aead_get_driver(void) \ { \ return &drv; \ } diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h index 96b32e2..5925a24 100644 --- a/include/drv/wd_digest_drv.h +++ b/include/drv/wd_digest_drv.h @@ -51,23 +51,13 @@ struct wd_digest_msg { __u64 long_data_len; };
-struct wd_digest_driver { - const char *drv_name; - const char *alg_name; - __u32 drv_ctx_size; - int (*init)(void *conf, void *priv); - void (*exit)(void *priv); - int (*digest_send)(handle_t ctx, void *digest_msg); - int (*digest_recv)(handle_t ctx, void *digest_msg); -}; - -void wd_digest_set_driver(struct wd_digest_driver *drv); -struct wd_digest_driver *wd_digest_get_driver(void); +void wd_digest_set_driver(struct wd_alg_driver *drv); +struct wd_alg_driver *wd_digest_get_driver(void); struct wd_digest_msg *wd_digest_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV #define WD_DIGEST_SET_DRIVER(drv) \ -struct wd_digest_driver *wd_digest_get_driver(void) \ +struct wd_alg_driver *wd_digest_get_driver(void) \ { \ return &drv; \ } diff --git a/include/wd_alg.h b/include/wd_alg.h index e25e191..3aa0f77 100644 --- a/include/wd_alg.h +++ b/include/wd_alg.h @@ -37,6 +37,7 @@ enum alg_priority { * algorithm business and requires queues to be executed separately * @priv_size: parameter memory size passed between the internal * interfaces of the driver + * @priv: pointer of priv ctx * @fallback: soft calculation driver handle when performing soft * calculation supplement * @init: callback interface for initializing device drivers @@ -55,15 +56,36 @@ struct wd_alg_driver { int queue_num; int op_type_num; int priv_size; + void *priv; handle_t fallback;
- int (*init)(void *conf, void *priv); - void (*exit)(void *priv); - int (*send)(handle_t ctx, void *drv_msg); - int (*recv)(handle_t ctx, void *drv_msg); + int (*init)(struct wd_alg_driver *drv, void *conf); + void (*exit)(struct wd_alg_driver *drv); + int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg); + int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg); int (*get_usage)(void *param); };
+inline int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf) +{ + return drv->init(drv, conf); +} + +inline void wd_alg_driver_exit(struct wd_alg_driver *drv) +{ + drv->exit(drv); +} + +inline int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + return drv->send(drv, ctx, msg); +} + +inline int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + return drv->recv(drv, ctx, msg); +} + int wd_alg_driver_register(struct wd_alg_driver *drv); void wd_alg_driver_unregister(struct wd_alg_driver *drv);
@@ -80,6 +102,7 @@ struct wd_alg_list {
struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask); void wd_release_drv(struct wd_alg_driver *drv); +struct wd_alg_driver *wd_find_drv(char *drv_name, char *alg_name);
bool wd_drv_alg_support(const char *alg_name, struct wd_alg_driver *drv); diff --git a/include/wd_util.h b/include/wd_util.h index a730f36..4d76ef2 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -110,8 +110,10 @@ struct wd_ctx_attr { };
struct wd_msg_handle { - int (*send)(handle_t sess, void *msg); - int (*recv)(handle_t sess, void *msg); + int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg); + int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg); + // int (*send)(handle_t sess, void *msg); + // int (*recv)(handle_t sess, void *msg); };
struct wd_init_attrs { @@ -363,7 +365,7 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en); * * Return 0 if successful or less than 0 otherwise. */ -int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, +int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle, handle_t ctx, void *msg, __u64 *balance, bool epoll_en);
/** diff --git a/libwd.map b/libwd.map index 5522ec0..cdfdf7e 100644 --- a/libwd.map +++ b/libwd.map @@ -45,9 +45,16 @@ global: wd_alg_driver_unregister; wd_request_drv; wd_release_drv; + wd_find_drv; wd_drv_alg_support; wd_enable_drv; wd_disable_drv; wd_get_alg_head; + + uadk_adapter_alloc; + uadk_adapter_free; + uadk_adapter_set_mode; + uadk_adapter_attach_worker; + uadk_adapter_parse; local: *; }; diff --git a/wd_aead.c b/wd_aead.c index 9b80922..55c2308 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -6,6 +6,8 @@
#include <stdlib.h> #include <pthread.h> + +#include "adapter.h" #include "include/drv/wd_aead_drv.h" #include "wd_aead.h"
@@ -33,7 +35,7 @@ struct wd_aead_setting { enum wd_status status; struct wd_ctx_config_internal config; struct wd_sched sched; - struct wd_aead_driver *driver; + struct wd_alg_driver *driver; struct wd_async_msg_pool pool; void *sched_ctx; void *priv; @@ -79,7 +81,7 @@ static void __attribute__((destructor)) wd_aead_close_driver(void) } #endif
-void wd_aead_set_driver(struct wd_aead_driver *drv) +void wd_aead_set_driver(struct wd_alg_driver *drv) { wd_aead_setting.driver = drv; } @@ -396,9 +398,26 @@ static void wd_aead_clear_status(void)
int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) { - void *priv; - bool flag; + struct wd_alg_driver *adapter = NULL; + char lib_path[PATH_STR_SIZE]; + char *alg_name = "aead"; + char *drv_name = "hisi_sec2"; int ret; + bool flag; + + ret = wd_get_lib_file_path("libhisi_sec2.so", lib_path, false); + if (ret) + return ret; + adapter = uadk_adapter_alloc(); + if (!adapter) + return -WD_EINVAL; + + ret = uadk_adapter_parse(adapter, lib_path, drv_name, alg_name); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to parse adapter\n"); + return -WD_EINVAL; + }
pthread_atfork(NULL, NULL, wd_aead_clear_status);
@@ -435,27 +454,18 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret < 0) goto out_clear_sched;
- /* init ctx related resources in specific driver */ - priv = calloc(1, wd_aead_setting.driver->drv_ctx_size); - if (!priv) { - ret = -WD_ENOMEM; - goto out_clear_pool; - } - wd_aead_setting.priv = priv; - - ret = wd_aead_setting.driver->init(&wd_aead_setting.config, priv); + // ret = wd_aead_setting.driver->init(&wd_aead_setting.config, priv); + ret = wd_alg_driver_init(adapter, &wd_aead_setting.config); if (ret < 0) { WD_ERR("failed to init aead dirver!\n"); - goto out_free_priv; + goto out_clear_pool; }
wd_alg_set_init(&wd_aead_setting.status); + wd_aead_setting.driver = adapter;
return 0;
-out_free_priv: - free(priv); - wd_aead_setting.priv = NULL; out_clear_pool: wd_uninit_async_request_pool(&wd_aead_setting.pool); out_clear_sched: @@ -469,14 +479,8 @@ out_clear_init:
void wd_aead_uninit(void) { - void *priv = wd_aead_setting.priv; - - if (!priv) - return; - - wd_aead_setting.driver->exit(priv); - wd_aead_setting.priv = NULL; - free(priv); + wd_alg_driver_exit(wd_aead_setting.driver); + uadk_adapter_free(wd_aead_setting.driver);
wd_uninit_async_request_pool(&wd_aead_setting.pool); wd_clear_sched(&wd_aead_setting.sched); @@ -517,11 +521,11 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_msg_handle msg_handle; int ret;
- msg_handle.send = wd_aead_setting.driver->aead_send; - msg_handle.recv = wd_aead_setting.driver->aead_recv; + msg_handle.send = wd_aead_setting.driver->send; + msg_handle.recv = wd_aead_setting.driver->recv;
pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, + ret = wd_handle_msg_sync(wd_aead_setting.driver, &msg_handle, ctx->ctx, msg, NULL, wd_aead_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); return ret; @@ -597,7 +601,8 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) fill_request_msg(msg, req, sess); msg->tag = msg_id;
- ret = wd_aead_setting.driver->aead_send(ctx->ctx, msg); + // ret = wd_aead_setting.driver->aead_send(ctx->ctx, msg); + ret = wd_alg_driver_send(wd_aead_setting.driver, ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("failed to send BD, hw is err!\n"); @@ -645,7 +650,8 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx;
do { - ret = wd_aead_setting.driver->aead_recv(ctx->ctx, &resp_msg); + ret = wd_alg_driver_recv(wd_aead_setting.driver, ctx->ctx, &resp_msg); + // ret = wd_aead_setting.driver->aead_recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { diff --git a/wd_alg.c b/wd_alg.c index 5e4edaf..2a9f160 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -263,3 +263,29 @@ void wd_release_drv(struct wd_alg_driver *drv) pthread_mutex_unlock(&mutex); }
+struct wd_alg_driver *wd_find_drv(char *drv_name, char *alg_name) +{ + struct wd_alg_list *head = &alg_list_head; + struct wd_alg_list *pnext = head->next; + struct wd_alg_driver *drv = NULL; + + if (!pnext || !alg_name) { + WD_ERR("invalid: request alg param is error!\n"); + return NULL; + } + + pthread_mutex_lock(&mutex); + while (pnext) { + if (!strcmp(alg_name, pnext->alg_name) && + !strcmp(drv_name, pnext->drv_name)) { + drv = pnext->drv; + break; + } + pnext = pnext->next; + } + + pthread_mutex_unlock(&mutex); + + return drv; +} + diff --git a/wd_cipher.c b/wd_cipher.c index eca9711..138aad1 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -9,6 +9,7 @@ #include <sched.h> #include "include/drv/wd_cipher_drv.h" #include "wd_cipher.h" +#include "adapter.h"
#define XTS_MODE_KEY_DIVISOR 2 #define SM4_KEY_SIZE 16 @@ -89,8 +90,9 @@ static void wd_cipher_close_driver(void)
static int wd_cipher_open_driver(void) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "cbc(aes)"; + struct wd_alg_driver *adapter = NULL; + char *alg_name = "cbc(aes)"; + char *drv_name = "hisi_sec2"; char lib_path[PATH_STR_SIZE]; int ret;
@@ -98,13 +100,24 @@ static int wd_cipher_open_driver(void) * Compatible with the normal acquisition of device * drivers in the init interface */ - if (wd_cipher_setting.dlh_list) - return 0; + //if (wd_cipher_setting.dlh_list) + // return 0;
ret = wd_get_lib_file_path("libhisi_sec.so", lib_path, false); if (ret) return ret;
+ adapter = uadk_adapter_alloc(); + if (!adapter) + return -WD_EINVAL; + + ret = uadk_adapter_parse(adapter, lib_path, drv_name, alg_name); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to parse adapter\n"); + return -WD_EINVAL; + } +/* wd_cipher_setting.dlhandle = dlopen(lib_path, RTLD_NOW); if (!wd_cipher_setting.dlhandle) { WD_ERR("failed to open libhisi_sec.so, %s\n", dlerror()); @@ -117,8 +130,8 @@ static int wd_cipher_open_driver(void) WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } - - wd_cipher_setting.driver = driver; +*/ + wd_cipher_setting.driver = adapter;
return 0; } @@ -304,9 +317,12 @@ static int wd_cipher_common_init(struct wd_ctx_config *config, if (ret < 0) goto out_clear_sched;
+ ret = wd_alg_driver_init(wd_cipher_setting.driver, &wd_cipher_setting.config); + /* ret = wd_alg_init_driver(&wd_cipher_setting.config, wd_cipher_setting.driver, &wd_cipher_setting.priv); + */ if (ret) goto out_clear_pool;
@@ -334,8 +350,12 @@ static void wd_cipher_common_uninit(void) /* unset config, sched, driver */ wd_clear_sched(&wd_cipher_setting.sched);
+ wd_alg_driver_exit(wd_cipher_setting.driver); + uadk_adapter_free(wd_cipher_setting.driver); + /* wd_alg_uninit_driver(&wd_cipher_setting.config, wd_cipher_setting.driver, &priv); + */ }
int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -582,7 +602,7 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, msg_handle.recv = wd_cipher_setting.driver->recv;
pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, + ret = wd_handle_msg_sync(wd_cipher_setting.driver, &msg_handle, ctx->ctx, msg, NULL, wd_cipher_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); return ret; @@ -658,7 +678,8 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) fill_request_msg(msg, req, sess); msg->tag = msg_id;
- ret = wd_cipher_setting.driver->send(ctx->ctx, msg); + ret = wd_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg); + // ret = wd_cipher_setting.driver->send(ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("wd cipher async send err!\n"); @@ -706,7 +727,8 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx;
do { - ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg); + ret = wd_alg_driver_recv(wd_cipher_setting.driver, ctx->ctx, &resp_msg); + // ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) return ret; else if (ret < 0) { diff --git a/wd_comp.c b/wd_comp.c index b7e0eb7..03e4ea1 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -12,6 +12,7 @@ #include <string.h> #include <time.h>
+#include "adapter.h" #include "drv/wd_comp_drv.h" #include "wd_comp.h"
@@ -38,6 +39,7 @@ struct wd_comp_sess { void *sched_key; };
+/* can we remove this? */ struct wd_comp_setting { enum wd_status status; struct wd_ctx_config_internal config; @@ -63,22 +65,34 @@ static void wd_comp_close_driver(void)
static int wd_comp_open_driver(void) { - struct wd_alg_driver *driver = NULL; + struct wd_alg_driver *adapter = NULL; char lib_path[PATH_STR_SIZE]; - const char *alg_name = "zlib"; + char *alg_name = "zlib"; + char *drv_name = "hisi_zip"; int ret;
/* * Compatible with the normal acquisition of device * drivers in the init interface */ - if (wd_comp_setting.dlh_list) - return 0; + //if (wd_comp_setting.dlh_list) + // return 0;
ret = wd_get_lib_file_path("libhisi_zip.so", lib_path, false); if (ret) return ret; + adapter = uadk_adapter_alloc(); + if (!adapter) + return -WD_EINVAL; + + ret = uadk_adapter_parse(adapter, lib_path, drv_name, alg_name); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to parse adapter\n"); + return -WD_EINVAL; + }
+/* wd_comp_setting.dlhandle = dlopen(lib_path, RTLD_NOW); if (!wd_comp_setting.dlhandle) { WD_ERR("failed to open libhisi_zip.so, %s\n", dlerror()); @@ -91,8 +105,8 @@ static int wd_comp_open_driver(void) WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } - - wd_comp_setting.driver = driver; +*/ + wd_comp_setting.driver = adapter;
return 0; } @@ -126,9 +140,13 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc if (ret < 0) goto out_clear_sched;
+ ret = wd_alg_driver_init(wd_comp_setting.driver, &wd_comp_setting.config); + + /* ret = wd_alg_init_driver(&wd_comp_setting.config, wd_comp_setting.driver, &wd_comp_setting.priv); + */ if (ret) goto out_clear_pool;
@@ -156,8 +174,11 @@ static void wd_comp_uninit_nolock(void) /* unset config, sched, driver */ wd_clear_sched(&wd_comp_setting.sched);
- wd_alg_uninit_driver(&wd_comp_setting.config, - wd_comp_setting.driver, &priv); + wd_alg_driver_exit(wd_comp_setting.driver); + uadk_adapter_free(wd_comp_setting.driver); + + // wd_alg_uninit_driver(&wd_comp_setting.config, + // wd_comp_setting.driver, &priv); }
int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -326,7 +347,8 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx;
do { - ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg); + ret = wd_alg_driver_recv(wd_comp_setting.driver, ctx->ctx, &resp_msg); + //ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg); if (unlikely(ret < 0)) { if (ret == -WD_HW_EACCESS) WD_ERR("wd comp recv hw error!\n"); @@ -561,7 +583,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, msg_handle.recv = wd_comp_setting.driver->recv;
pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, + ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx, msg, NULL, config->epoll_en); pthread_spin_unlock(&ctx->lock);
@@ -817,7 +839,8 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) msg->tag = tag; msg->stream_mode = WD_COMP_STATELESS;
- ret = wd_comp_setting.driver->send(ctx->ctx, msg); + ret = wd_alg_driver_send(wd_comp_setting.driver, ctx->ctx, msg); + //ret = wd_comp_setting.driver->send(ctx->ctx, msg); if (unlikely(ret < 0)) { WD_ERR("wd comp send error, ret = %d!\n", ret); goto fail_with_msg; diff --git a/wd_dh.c b/wd_dh.c index d45ac89..c0b6c55 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -353,7 +353,7 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req) msg_handle.recv = wd_dh_setting.driver->recv;
pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, + ret = wd_handle_msg_sync(wd_dh_setting.driver, &msg_handle, ctx->ctx, &msg, &balance, wd_dh_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); if (unlikely(ret)) @@ -399,7 +399,8 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) goto fail_with_msg; msg->tag = mid;
- ret = wd_dh_setting.driver->send(ctx->ctx, msg); + ret = wd_alg_driver_send(wd_dh_setting.driver, ctx->ctx, msg); + //ret = wd_dh_setting.driver->send(ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send dh BD, hw is err!\n"); @@ -449,7 +450,8 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx;
do { - ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg); + ret = wd_alg_driver_recv(wd_dh_setting.driver, ctx->ctx, &rcv_msg); + // ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (unlikely(ret)) { diff --git a/wd_digest.c b/wd_digest.c index 8c01709..cab6f94 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -8,6 +8,7 @@ #include <pthread.h> #include "include/drv/wd_digest_drv.h" #include "wd_digest.h" +#include "adapter.h"
#define XTS_MODE_KEY_DIVISOR 2 #define SM4_KEY_SIZE 16 @@ -41,7 +42,7 @@ struct wd_digest_setting { enum wd_status status; struct wd_ctx_config_internal config; struct wd_sched sched; - struct wd_digest_driver *driver; + struct wd_alg_driver *driver; struct wd_async_msg_pool pool; void *sched_ctx; void *priv; @@ -90,7 +91,7 @@ static void __attribute__((destructor)) wd_digest_close_driver(void) } #endif
-void wd_digest_set_driver(struct wd_digest_driver *drv) +void wd_digest_set_driver(struct wd_alg_driver *drv) { wd_digest_setting.driver = drv; } @@ -190,9 +191,26 @@ static void wd_digest_clear_status(void)
int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) { - void *priv; - bool flag; + struct wd_alg_driver *adapter = NULL; + char lib_path[PATH_STR_SIZE]; + char *alg_name = "digest"; + char *drv_name = "hisi_sec2"; int ret; + bool flag; + + ret = wd_get_lib_file_path("libhisi_sec2.so", lib_path, false); + if (ret) + return ret; + adapter = uadk_adapter_alloc(); + if (!adapter) + return -WD_EINVAL; + + ret = uadk_adapter_parse(adapter, lib_path, drv_name, alg_name); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to parse adapter\n"); + return -WD_EINVAL; + }
pthread_atfork(NULL, NULL, wd_digest_clear_status);
@@ -229,28 +247,33 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret < 0) goto out_clear_sched;
+ /* drv should alloc priv by itself */ /* init ctx related resources in specific driver */ +/* priv = calloc(1, wd_digest_setting.driver->drv_ctx_size); if (!priv) { ret = -WD_ENOMEM; goto out_clear_pool; } wd_digest_setting.priv = priv; +*/
- ret = wd_digest_setting.driver->init(&wd_digest_setting.config, priv); + ret = wd_alg_driver_init(adapter, &wd_digest_setting.config); + //ret = wd_digest_setting.driver->init(&wd_digest_setting.config, priv); if (ret < 0) { WD_ERR("failed to init digest dirver!\n"); goto out_free_priv; }
+ wd_digest_setting.driver = adapter; wd_alg_set_init(&wd_digest_setting.status);
return 0;
out_free_priv: - free(priv); +// free(priv); wd_digest_setting.priv = NULL; -out_clear_pool: +// out_clear_pool: wd_uninit_async_request_pool(&wd_digest_setting.pool); out_clear_sched: wd_clear_sched(&wd_digest_setting.sched); @@ -263,14 +286,18 @@ out_clear_init:
void wd_digest_uninit(void) { - void *priv = wd_digest_setting.priv; + struct wd_alg_driver *adapter = wd_digest_setting.driver; + //void *priv = wd_digest_setting.priv;
- if (!priv) - return; + //if (!priv) + // return;
- wd_digest_setting.driver->exit(priv); - wd_digest_setting.priv = NULL; - free(priv); + wd_alg_driver_exit(adapter); + // wd_digest_setting.driver->exit(wd_digest_setting.driver); + // wd_digest_setting.priv = NULL; + uadk_adapter_free(adapter); + + // free(priv);
wd_uninit_async_request_pool(&wd_digest_setting.pool);
@@ -404,11 +431,11 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds struct wd_msg_handle msg_handle; int ret;
- msg_handle.send = wd_digest_setting.driver->digest_send; - msg_handle.recv = wd_digest_setting.driver->digest_recv; + msg_handle.send = wd_digest_setting.driver->send; + msg_handle.recv = wd_digest_setting.driver->recv;
pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, + ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx, msg, NULL, wd_digest_setting.config.epoll_en); if (unlikely(ret)) goto out; @@ -493,7 +520,8 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) fill_request_msg(msg, req, dsess); msg->tag = msg_id;
- ret = wd_digest_setting.driver->digest_send(ctx->ctx, msg); + // ret = wd_digest_setting.driver->send(ctx->ctx, msg); + ret = wd_alg_driver_send(wd_digest_setting.driver, ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("failed to send BD, hw is err!\n"); @@ -541,8 +569,8 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx;
do { - ret = wd_digest_setting.driver->digest_recv(ctx->ctx, - &recv_msg); + ret = wd_alg_driver_recv(wd_digest_setting.driver, ctx->ctx, &recv_msg); + // ret = wd_digest_setting.driver->digest_recv(ctx->ctx, &recv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { diff --git a/wd_ecc.c b/wd_ecc.c index 57954e0..d5db5ad 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -1557,7 +1557,7 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req) msg_handle.recv = wd_ecc_setting.driver->recv;
pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, + ret = wd_handle_msg_sync(wd_ecc_setting.driver, &msg_handle, ctx->ctx, &msg, &balance, wd_ecc_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); if (unlikely(ret)) @@ -2237,7 +2237,8 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) goto fail_with_msg; msg->tag = mid;
- ret = wd_ecc_setting.driver->send(ctx->ctx, msg); + // ret = wd_ecc_setting.driver->send(ctx->ctx, msg); + ret = wd_alg_driver_send(wd_ecc_setting.driver, ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send ecc BD, hw is err!\n"); @@ -2285,7 +2286,8 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx;
do { - ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg); + ret = wd_alg_driver_recv(wd_ecc_setting.driver, ctx->ctx, &recv_msg); + // ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { diff --git a/wd_rsa.c b/wd_rsa.c index 77fe5c0..d402ecf 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -415,7 +415,7 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req) msg_handle.recv = wd_rsa_setting.driver->recv;
pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, + ret = wd_handle_msg_sync(wd_rsa_setting.driver, &msg_handle, ctx->ctx, &msg, &balance, wd_rsa_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); if (unlikely(ret)) @@ -461,7 +461,8 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) goto fail_with_msg; msg->tag = mid;
- ret = wd_rsa_setting.driver->send(ctx->ctx, msg); + ret = wd_alg_driver_send(wd_rsa_setting.driver, ctx->ctx, msg); + //ret = wd_rsa_setting.driver->send(ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send rsa BD, hw is err!\n"); @@ -509,7 +510,8 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx;
do { - ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg); + ret = wd_alg_driver_recv(wd_rsa_setting.driver, ctx->ctx, &recv_msg); + //ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { diff --git a/wd_util.c b/wd_util.c index dab4fc8..879612a 100644 --- a/wd_util.c +++ b/wd_util.c @@ -1785,7 +1785,7 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en) return 0; }
-int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, +int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle, handle_t ctx, void *msg, __u64 *balance, bool epoll_en) { __u64 timeout = WD_RECV_MAX_CNT_NOSLEEP; @@ -1795,7 +1795,7 @@ int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, if (balance) timeout = WD_RECV_MAX_CNT_SLEEP;
- ret = msg_handle->send(ctx, msg); + ret = msg_handle->send(drv, ctx, msg); if (unlikely(ret < 0)) { WD_ERR("failed to send msg to hw, ret = %d!\n", ret); return ret; @@ -1808,7 +1808,7 @@ int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, WD_ERR("wd ctx wait timeout(%d)!\n", ret); }
- ret = msg_handle->recv(ctx, msg); + ret = msg_handle->recv(drv, ctx, msg); if (ret == -WD_EAGAIN) { if (unlikely(rx_cnt++ >= timeout)) { WD_ERR("failed to recv msg: timeout!\n"); @@ -1915,13 +1915,16 @@ static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver) int wd_alg_init_driver(struct wd_ctx_config_internal *config, struct wd_alg_driver *driver, void **drv_priv) { - void *priv; +// void *priv; int ret;
+ /* driver should alloc ctx by itself */ /* Init ctx related resources in specific driver */ +/* priv = calloc(1, driver->priv_size); if (!priv) return -WD_ENOMEM; +*/
if (!driver->init) { driver->fallback = 0; @@ -1930,7 +1933,7 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config, goto err_alloc; }
- ret = driver->init(config, priv); + ret = driver->init(driver, config); if (ret < 0) { WD_ERR("driver init failed.\n"); goto err_alloc; @@ -1943,12 +1946,12 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config, WD_ERR("soft alg driver init failed.\n"); } } - *drv_priv = priv; + // *drv_priv = priv;
return 0;
err_alloc: - free(priv); + //free(priv); return ret; }
In order to simulate cpu instruction accelerator, this patch adds zlib drv, which does not require accelerator at all. So may not require wd_xxx_init, and ctx and sched which relates to queue.
Btw, zlib is required. apt-get install zlib1g-dev
Signed-off-by: Zhangfei Gao zhangfei.gao@linaro.org --- Makefile.am | 10 +++ drv/hisi_zlib.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 drv/hisi_zlib.c
diff --git a/Makefile.am b/Makefile.am index 3694f7c..11975b5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,9 @@ nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd
lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libhisi_zip.la \ libhisi_hpre.la libhisi_sec.la +if HAVE_ZLIB +lib_LTLIBRARIES+=libhisi_zlib.la +endif
libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \ v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \ @@ -68,6 +71,8 @@ libwd_comp_la_SOURCES=wd_comp.c wd_comp.h wd_comp_drv.h wd_util.c wd_util.h \ libhisi_zip_la_SOURCES=drv/hisi_comp.c hisi_comp.h drv/hisi_qm_udrv.c \ hisi_qm_udrv.h wd_comp_drv.h
+libhisi_zlib_la_SOURCES=drv/hisi_zlib.c + libwd_crypto_la_SOURCES=wd_cipher.c wd_cipher.h wd_cipher_drv.h \ wd_aead.c wd_aead.h wd_aead_drv.h \ wd_rsa.c wd_rsa.h wd_rsa_drv.h \ @@ -94,6 +99,8 @@ libwd_comp_la_DEPENDENCIES = libwd.la
libhisi_zip_la_LIBADD = -ldl
+libhisi_zlib_la_LIBADD = -ldl -lz + libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma libwd_crypto_la_DEPENDENCIES = libwd.la
@@ -122,6 +129,9 @@ libwd_crypto_la_DEPENDENCIES= libwd.la libhisi_zip_la_LIBADD= -ldl libhisi_zip_la_LDFLAGS=$(UADK_VERSION)
+libhisi_zlib_la_LIBADD= -ldl -lz +libhisi_zlib_la_LDFLAGS=$(UADK_VERSION) + libhisi_sec_la_LIBADD= -lwd -lwd_crypto libhisi_sec_la_LDFLAGS=$(UADK_VERSION) libhisi_sec_la_DEPENDENCIES= libwd.la libwd_crypto.la diff --git a/drv/hisi_zlib.c b/drv/hisi_zlib.c new file mode 100644 index 0000000..2281ab1 --- /dev/null +++ b/drv/hisi_zlib.c @@ -0,0 +1,167 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright 2023-2024 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2023-2024 Linaro ltd. + */ +#include <stdlib.h> +#include <stdio.h> +#include <zlib.h> + +#include "drv/wd_comp_drv.h" + +struct hisi_zlib_priv { + int windowbits; +}; + +static int hisi_zlib_init(struct wd_alg_driver *drv, void *conf) +{ + struct hisi_zlib_priv *priv; + + priv = malloc(sizeof(struct hisi_zlib_priv)); + if (!priv) + return -ENOMEM; + + if (strcmp(drv->alg_name, "zlib") == 0) + priv->windowbits = 15; + else if (strcmp(drv->alg_name, "deflate") == 0) + priv->windowbits = -15; + else if (strcmp(drv->alg_name, "gzip") == 0) + priv->windowbits = 15 + 16; + + drv->priv = priv; + + return 0; +} +static void hisi_zlib_exit(struct wd_alg_driver *drv) +{ + struct hisi_zlib_priv *priv = (struct hisi_zlib_priv *)drv->priv; + + free(priv); +} + +static int hisi_zlib_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg) +{ + struct hisi_zlib_priv *priv = (struct hisi_zlib_priv *)drv->priv; + struct wd_comp_msg *msg = comp_msg; + z_stream strm; + int ret; + + memset(&strm, 0, sizeof(z_stream)); + + strm.next_in = msg->req.src; + strm.avail_in = msg->req.src_len; + strm.next_out = msg->req.dst; + strm.avail_out = msg->req.dst_len; + + if (msg->req.op_type == WD_DIR_COMPRESS) { + /* deflate */ + + ret = deflateInit2(&strm, Z_BEST_SPEED, Z_DEFLATED, priv->windowbits, + 8, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) { + printf("deflateInit2: %d\n", ret); + return -EINVAL; + } + + do { + ret = deflate(&strm, Z_FINISH); + if ((ret == Z_STREAM_ERROR) || (ret == Z_BUF_ERROR)) { + printf("defalte error %d - %s\n", ret, strm.msg); + ret = -ENOSR; + break; + } else if (!strm.avail_in) { + if (ret != Z_STREAM_END) + printf("deflate unexpected return: %d\n", ret); + ret = 0; + break; + } else if (!strm.avail_out) { + printf("deflate out of memory\n"); + ret = -ENOSPC; + break; + } + } while (ret == Z_OK); + + deflateEnd(&strm); + + } else { + /* inflate */ + + /* Window size of 15, +32 for auto-decoding gzip/zlib */ + ret = inflateInit2(&strm, 15 + 32); + if (ret != Z_OK) { + printf("zlib inflateInit: %d\n", ret); + return -EINVAL; + } + + do { + ret = inflate(&strm, Z_NO_FLUSH); + if ((ret < 0) || (ret == Z_NEED_DICT)) { + printf("zlib error %d - %s\n", ret, strm.msg); + ret = -EINVAL; + break; + } + if (!strm.avail_out) { + if (!strm.avail_in || (ret == Z_STREAM_END)) { + ret = 0; + break; + } + printf("%s: avail_out is empty!\n", __func__); + ret = -EINVAL; + break; + } + } while (strm.avail_in && (ret != Z_STREAM_END)); + inflateEnd(&strm); + } + + msg->produced = msg->req.dst_len - strm.avail_out; + msg->in_cons = msg->req.src_len; + + return ret; +} +static int hisi_zlib_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + /* + * recv just return since cpu does not support async, + * once send func return, the operation is done + */ + return 0; +} + +#define GEN_ZLIB_ALG_DRIVER(zlib_alg_name) \ +{\ + .drv_name = "hisi_zlib",\ + .alg_name = zlib_alg_name,\ + .priority = UADK_ALG_SOFT,\ + .init = hisi_zlib_init,\ + .exit = hisi_zlib_exit,\ + .send = hisi_zlib_send,\ + .recv = hisi_zlib_recv,\ +} + +static struct wd_alg_driver zlib_alg_driver[] = { + GEN_ZLIB_ALG_DRIVER("zlib"), + GEN_ZLIB_ALG_DRIVER("gzip"), + GEN_ZLIB_ALG_DRIVER("deflate"), +}; + +static void __attribute__((constructor)) hisi_zlib_probe(void) +{ + int alg_num = ARRAY_SIZE(zlib_alg_driver); + int i, ret; + + for (i = 0; i < alg_num; i++) { + ret = wd_alg_driver_register(&zlib_alg_driver[i]); + if (ret) + fprintf(stderr, "Error: register zlib %s failed!\n", + zlib_alg_driver[i].alg_name); + } +} + +static void __attribute__((destructor)) hisi_zlib_remove(void) +{ + int alg_num = ARRAY_SIZE(zlib_alg_driver); + int i; + + for (i = 0; i < alg_num; i++) + wd_alg_driver_unregister(&zlib_alg_driver[i]); +}
deflate work ./sample/uadk_comp --lib /tmp/build/lib/libhisi_zlib.so --drv hisi_zlib --optype 0 --alg gzip <Makefile >out
infalte still has issue(zlib error -5 - (null)), for demo purpose ./sample/uadk_comp --lib /tmp/build/lib/libhisi_zlib.so --drv hisi_zlib --optype 1 --alg gzip <out >dst
vimdiff Makefile dst
Signed-off-by: Zhangfei Gao zhangfei.gao@linaro.org --- include/wd_comp.h | 3 ++ libwd_comp.map | 2 ++ sample/uadk_comp.c | 58 ++++++++++++++++++++++++------- wd_comp.c | 86 +++++++++++++++++++++++++++++++++++----------- 4 files changed, 117 insertions(+), 32 deletions(-)
diff --git a/include/wd_comp.h b/include/wd_comp.h index 45b0d0b..2774eb4 100644 --- a/include/wd_comp.h +++ b/include/wd_comp.h @@ -256,6 +256,9 @@ void wd_comp_ctx_num_uninit(void); int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable);
+int wd_comp_attach_worker(char *lib_path, char *drv_name, char *alg_name); +void wd_comp_stop_worker(void); + #ifdef __cplusplus } #endif diff --git a/libwd_comp.map b/libwd_comp.map index ce3e051..01a20ca 100644 --- a/libwd_comp.map +++ b/libwd_comp.map @@ -37,5 +37,7 @@ global: wd_inflateReset; wd_inflateEnd;
+ wd_comp_attach_worker; + wd_comp_stop_worker; local: *; }; diff --git a/sample/uadk_comp.c b/sample/uadk_comp.c index 908c7bc..9b9e593 100644 --- a/sample/uadk_comp.c +++ b/sample/uadk_comp.c @@ -21,6 +21,8 @@
struct request_config { char algname[MAX_ALG_LEN]; + char drvname[MAX_ALG_LEN]; + char libname[MAX_ALG_LEN]; enum wd_comp_alg_type alg; enum wd_comp_level complv; enum wd_comp_op_type optype; @@ -127,6 +129,18 @@ out: return NULL; }
+static struct uacce_dev_list *get_dev_list_from_drv(char *drv_name, char *alg_name) +{ + /* Todo + * need realize wd_get_accel_list(const char *drv_name) + */ + + // hack for simple + if (!drv_name || (strcmp(drv_name, "hisi_zlib") == 0)) + return NULL; + else + return get_dev_list(alg_name); +} static int lib_poll_func(__u32 pos, __u32 expect, __u32 *count) { int ret; @@ -386,10 +400,19 @@ static int operation(FILE *source, FILE *dest) { int ret;
- ret = uadk_comp_ctx_init(); - if (ret) { - fprintf(stderr, "%s fail to init ctx!\n", __func__); - return ret; + if (config.list) { + /* only hardware accelerator need ctx and sched for queue resource */ + ret = uadk_comp_ctx_init(); + if (ret) { + fprintf(stderr, "%s fail to init ctx!\n", __func__); + return ret; + } + } else { + ret = wd_comp_attach_worker(config.libname, config.drvname, config.algname); + if (ret) { + fprintf(stderr, "%s fail to attach worker!\n", __func__); + return ret; + } }
ret = uadk_comp_sess_init(); @@ -420,7 +443,11 @@ out_sess_uninit: uadk_comp_sess_uninit();
out_ctx_uninit: - uadk_comp_ctx_uninit(); + + if (config.list) + uadk_comp_ctx_uninit(); + else + wd_comp_stop_worker();
return ret; } @@ -438,6 +465,8 @@ static void print_help(void) "The window size for compression(8K as default).\n" "\t[--complv]: " "The compression level(8 as default).\n" + "\t[--drv]: The driver using for the alg.\n" + "\t[--lib]: shared library of the driver.\n" "\t[--help] " "Print Help (this message) and exit\n" ""); @@ -455,6 +484,9 @@ int main(int argc, char *argv[]) {"complv", required_argument, 0, 2}, {"optype", required_argument, 0, 3}, {"winsize", required_argument, 0, 4}, + {"drv", required_argument, 0, 5}, + {"lib", required_argument, 0, 6}, + {0, 0, 0, 0} };
@@ -468,13 +500,7 @@ int main(int argc, char *argv[]) help = 1; break; case 1: - config.list = get_dev_list(optarg); - if (!config.list) { - cowfail("Can't find your algorithm!\n"); - help = 1; - } else { - strcpy(config.algname, optarg); - } + strcpy(config.algname, optarg); break; case 2: config.complv = strtol(optarg, NULL, 0); @@ -485,6 +511,12 @@ int main(int argc, char *argv[]) case 4: config.winsize = strtol(optarg, NULL, 0); break; + case 5: + strcpy(config.drvname, optarg); + break; + case 6: + strcpy(config.libname, optarg); + break; default: help = 1; cowfail("bad input test parameter!\n"); @@ -497,6 +529,8 @@ int main(int argc, char *argv[]) exit(-1); }
+ config.list = get_dev_list_from_drv(config.drvname, config.algname); + ret = operation(stdin, stdout); if (ret) cowfail("So sad for we do something wrong!\n"); diff --git a/wd_comp.c b/wd_comp.c index 03e4ea1..ad9e006 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -63,6 +63,45 @@ static void wd_comp_close_driver(void) } }
+int wd_comp_attach_worker(char *lib_path, char *drv_name, char *alg_name) +{ + struct wd_alg_driver *adapter = wd_comp_setting.driver; + int ret; + + if (!adapter) { + wd_comp_setting.driver = adapter = uadk_adapter_alloc(); + if (!adapter) + return -WD_EINVAL; + } + + ret = uadk_adapter_parse(adapter, lib_path, drv_name, alg_name); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to parse adapter\n"); + return -WD_EINVAL; + } + + ret = wd_alg_driver_init(adapter, NULL); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to init adapter\n"); + return -WD_EINVAL; + } + + return 0; +} + +void wd_comp_stop_worker(void) +{ + struct wd_alg_driver *adapter = wd_comp_setting.driver; + + if (adapter) { + wd_alg_driver_exit(adapter); + uadk_adapter_free(adapter); + wd_comp_setting.driver = NULL; + } +} + static int wd_comp_open_driver(void) { struct wd_alg_driver *adapter = NULL; @@ -430,12 +469,14 @@ handle_t wd_comp_alloc_sess(struct wd_comp_sess_setup *setup) sess->win_sz = setup->win_sz; sess->stream_pos = WD_COMP_STREAM_NEW;
- /* Some simple scheduler don't need scheduling parameters */ - sess->sched_key = (void *)wd_comp_setting.sched.sched_init( - wd_comp_setting.sched.h_sched_ctx, setup->sched_param); - if (WD_IS_ERR(sess->sched_key)) { - WD_ERR("failed to init session schedule key!\n"); - goto sched_err; + if (wd_comp_setting.sched.sched_init) { + /* Some simple scheduler don't need scheduling parameters */ + sess->sched_key = (void *)wd_comp_setting.sched.sched_init( + wd_comp_setting.sched.h_sched_ctx, setup->sched_param); + if (WD_IS_ERR(sess->sched_key)) { + WD_ERR("failed to init session schedule key!\n"); + goto sched_err; + } }
return (handle_t)sess; @@ -569,23 +610,28 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, __u32 idx; int ret;
- idx = wd_comp_setting.sched.pick_next_ctx(h_sched_ctx, - sess->sched_key, - CTX_MODE_SYNC); - ret = wd_check_ctx(config, CTX_MODE_SYNC, idx); - if (unlikely(ret)) - return ret; - - wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); - ctx = config->ctxs + idx; - msg_handle.send = wd_comp_setting.driver->send; msg_handle.recv = wd_comp_setting.driver->recv;
- pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx, msg, - NULL, config->epoll_en); - pthread_spin_unlock(&ctx->lock); + if (wd_comp_setting.sched.pick_next_ctx) { + idx = wd_comp_setting.sched.pick_next_ctx(h_sched_ctx, + sess->sched_key, + CTX_MODE_SYNC); + ret = wd_check_ctx(config, CTX_MODE_SYNC, idx); + if (unlikely(ret)) + return ret; + + wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + pthread_spin_lock(&ctx->lock); + ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx, msg, + NULL, config->epoll_en); + pthread_spin_unlock(&ctx->lock); + } else { + ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, 0, msg, + NULL, config->epoll_en); + }
return ret; }
driver can only update length msg->produced = msg->req.dst_len - strm.avail_out; msg->in_cons = msg->req.src_len; status is decided by caller
// not sure about this patch, with this patch, compress and decompress are both OK
./sample/uadk_comp --lib /tmp/build/lib/libhisi_zlib.so --drv hisi_zlib --optype 0 --alg gzip <Makefile >out ./sample/uadk_comp --lib /tmp/build/lib/libhisi_zlib.so --drv hisi_zlib --optype 1 --alg gzip <out >dst vimdiff Makefile dst
Signed-off-by: Zhangfei Gao zhangfei.gao@linaro.org --- wd_comp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd_comp.c b/wd_comp.c index ad9e006..ef6cc7f 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -795,7 +795,7 @@ static void wd_do_comp_strm_end_check(struct wd_comp_sess *sess, req->src_len == src_len) sess->stream_pos = WD_COMP_STREAM_NEW; else if (req->op_type == WD_DIR_DECOMPRESS && - req->status == WD_STREAM_END) + req->src_len == src_len) sess->stream_pos = WD_COMP_STREAM_NEW; }
On Wed, 12 Apr 2023 at 14:47, Zhangfei Gao zhangfei.gao@linaro.org wrote:
This is only for demo of the adapter proposal Goals
- support cpu instruction accelerator
- support switch between hardware accelerator and cpu instruction
Status
- Existing hardware accelerator are supported.
- Add a hisi_zlib driver to simulate cpu instruction, supported by uadk_comp
Todo:
- how to better coexist with existing wd_xxx_init.
wd_xxx_init is not a must, only required for hardware resources. On platform only support cpu, wd_xxx_init can be used, but the failure should not be treated as error.
how to parse workers from config, or environment.
how to switch between hardware and cpu, ie, add policy.
Now only simply add round-robin policy: adapter_roundrobin.c The plan will add at least adapter_threshold.c, ...
我理解wd_xxx_init / init2都只能加载一个默认硬件驱动, 区别init只能选择硬件加速器, init2带type,可以选其他类型, 加载多个驱动做不到,也不一定是用户期望的。 比如平台上同时有加速器,指令集,支持gzip,wd_xxx_init是一次性全load,还是根据优先级选最高的,真的帮用户做决定么。
或者说wd_xxx_init只是初始化硬件资源,再加载这个硬件加速器, (这个不是必须的,只有在使用硬件加速器的时候) 而加载其他驱动则有其他api来做。
关于ctx,sched, 根据定义ctx就是硬件资源,sched则是选择ctx。 sess是软件资源。 也就是如果只使用cpu指令集,则ctx, sched可以不选。 所以现在uadk库需要考虑ctx, sched为空的情况。
wd.h
/**
* wd_request_ctx() - Request a communication context from a device.
* @dev: Indicate one device.
*
* Return the handle of related context or NULL otherwise.
*
* The context is communication context between user and hardware. One context
* must be got before doing any task. This function can be used among multiple
* threads. dev should be got from wd_get_accel_list() firstly.
*/
handle_t wd_request_ctx(struct uacce_dev *dev);
wd_alg_common.h
/**
* struct wd_comp_sched - Define a scheduler.
* @name: Name of this scheduler.
* @sched_policy: Method for scheduler to perform scheduling
* @sched_init: inited the scheduler input parameters.
* @pick_next_ctx: Pick the proper ctx which a request will be sent to.
* config points to the ctx config; sched_ctx points to
* scheduler context; req points to the request. Return
* the proper ctx pos in wd_ctx_config.
* (fix me: modify req to request?)
* @poll_policy: Define the polling policy. config points to the ctx
* config; sched_ctx points to scheduler context; Return
* number of polled request.
*/
struct wd_sched {
const char *name;
int sched_policy;
handle_t (*sched_init)(handle_t h_sched_ctx, void *sched_param);
__u32 (*pick_next_ctx)(handle_t h_sched_ctx,
void *sched_key,
const int sched_mode);
int (*poll_policy)(handle_t h_sched_ctx, __u32 expect, __u32 *count);
handle_t h_sched_ctx;
};
2023年4月14日 09:52,Zhangfei Gao zhangfei.gao@linaro.org 写道:
On Wed, 12 Apr 2023 at 14:47, Zhangfei Gao <zhangfei.gao@linaro.org mailto:zhangfei.gao@linaro.org> wrote:
This is only for demo of the adapter proposal Goals
- support cpu instruction accelerator
- support switch between hardware accelerator and cpu instruction
Status
- Existing hardware accelerator are supported.
- Add a hisi_zlib driver to simulate cpu instruction, supported by uadk_comp
Todo:
- how to better coexist with existing wd_xxx_init.
wd_xxx_init is not a must, only required for hardware resources. On platform only support cpu, wd_xxx_init can be used, but the failure should not be treated as error.
how to parse workers from config, or environment.
how to switch between hardware and cpu, ie, add policy.
Now only simply add round-robin policy: adapter_roundrobin.c The plan will add at least adapter_threshold.c, ...
我理解wd_xxx_init / init2都只能加载一个默认硬件驱动, 区别init只能选择硬件加速器, init2带type,可以选其他类型, 加载多个驱动做不到,也不一定是用户期望的。 比如平台上同时有加速器,指令集,支持gzip,wd_xxx_init是一次性全load,还是根据优先级选最高的,真的帮用户做决定么。
或者说wd_xxx_init只是初始化硬件资源,再加载这个硬件加速器, (这个不是必须的,只有在使用硬件加速器的时候) 而加载其他驱动则有其他api来做。
关于ctx,sched, 根据定义ctx就是硬件资源,sched则是选择ctx。 sess是软件资源。 也就是如果只使用cpu指令集,则ctx, sched可以不选。 所以现在uadk库需要考虑ctx, sched为空的情况。
wd.h
/**
wd_request_ctx() - Request a communication context from a device.
@dev: Indicate one device.
Return the handle of related context or NULL otherwise.
The context is communication context between user and hardware. One context
must be got before doing any task. This function can be used among multiple
threads. dev should be got from wd_get_accel_list() firstly.
*/
handle_t wd_request_ctx(struct uacce_dev *dev);
wd_alg_common.h
/**
struct wd_comp_sched - Define a scheduler.
@name: Name of this scheduler.
@sched_policy: Method for scheduler to perform scheduling
@sched_init: inited the scheduler input parameters.
@pick_next_ctx: Pick the proper ctx which a request will be sent to.
config points to the ctx config; sched_ctx points to
scheduler context; req points to the request. Return
the proper ctx pos in wd_ctx_config.
(fix me: modify req to request?)
@poll_policy: Define the polling policy. config points to the ctx
config; sched_ctx points to scheduler context; Return
number of polled request.
*/
struct wd_sched {
const char *name;
int sched_policy;
handle_t (*sched_init)(handle_t h_sched_ctx, void *sched_param);
__u32 (*pick_next_ctx)(handle_t h_sched_ctx,
void *sched_key, const int sched_mode);
int (*poll_policy)(handle_t h_sched_ctx, __u32 expect, __u32 *count);
handle_t h_sched_ctx;
}; _______________________________________________ Acc mailing list -- acc@lists.linaro.org mailto:acc@lists.linaro.org To unsubscribe send an email to acc-leave@lists.linaro.org mailto:acc-leave@lists.linaro.org