summaryrefslogtreecommitdiff
path: root/src/entry/Maat_api.cpp
diff options
context:
space:
mode:
authorzhengchao <[email protected]>2021-07-19 02:15:18 +0800
committerzhengchao <[email protected]>2021-07-19 20:55:12 +0800
commit1e2e3a1798e4a4af5cdea49339bf6e7926bb7d85 (patch)
treef97f87f0c87e42875d8f28b5a7340d98052f8073 /src/entry/Maat_api.cpp
parentebd07cc5a7acaeb06f6630bbcf6225f54f0081c2 (diff)
改进Hierarchy的多线程扫描性能: Hierarchy使用rwlock来保证更新线程和扫描线程间的线程安全, 测试发现在不发生读写锁冲突的情况下, 读写锁的固有开销会导致并发扫描速度降低。
reference: https://stackoverflow.com/questions/11866486/how-many-simultaneous-readers-can-a-pthread-rwlock-have
Diffstat (limited to 'src/entry/Maat_api.cpp')
-rw-r--r--src/entry/Maat_api.cpp41
1 files changed, 10 insertions, 31 deletions
diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp
index be4e719..9909dd0 100644
--- a/src/entry/Maat_api.cpp
+++ b/src/entry/Maat_api.cpp
@@ -369,6 +369,9 @@ int fill_region_hit_detail(const char* scan_buff, const Maat_hierarchy_compile_m
struct Maat_hit_detail_t *hit_detail, int detail_num,
struct Maat_scanner* scanner)
{
+
+ //Stop support this feature. 2021-7-19
+/*
int i=0;
size_t j=0;
char r_in_c_flag[region_cnt];
@@ -389,7 +392,7 @@ int fill_region_hit_detail(const char* scan_buff, const Maat_hierarchy_compile_m
Maat_hit_path_init(&condition);
condition.Nth_scan=Nth_scan;
condition.compile_id=compile[i].config_id;
- hit_path_cnt=Maat_hierarchy_hit_path_select0(mid, &condition, hit_paths, MAX_SCANNER_HIT_NUM);
+ hit_path_cnt=Maat_hierarchy_get_hit_paths(mid, &condition, hit_paths, MAX_SCANNER_HIT_NUM);
for(j=0; j<hit_path_cnt && j<MAAT_MAX_HIT_RULE_NUM; j++)
{
Nth_hit_region=hit_paths[j]->Nth_hit_region;
@@ -417,6 +420,8 @@ int fill_region_hit_detail(const char* scan_buff, const Maat_hierarchy_compile_m
}
}
return i;
+ */
+ return 0;
}
struct _OUTER_scan_status_t* _make_outer_status(_Maat_feather_t *feather, int thread_num)
@@ -2441,24 +2446,6 @@ int Maat_read_rule(Maat_feather_t feather, const struct Maat_rule_t* rule, enum
return ret;
}
-int Maat_apply_scan_status(Maat_feather_t feather, scan_status_t *mid,
- struct Maat_rule_t*result, int rule_num, int thread_num)
-{
- struct _OUTER_scan_status_t* _mid=(struct _OUTER_scan_status_t*)(*mid);
- struct _Maat_feather_t* _feather=(_Maat_feather_t*)feather;
- struct scan_region_hit_wraper region_hit_wraper;
- int ret=0;
- if(!_mid||! (_mid->compile_mid))
- {
- return 0;
- }
- memset(&region_hit_wraper, 0, sizeof(region_hit_wraper));
- region_hit_wraper.Nth_scan=_mid->scan_cnt;
- region_hit_wraper.n_hit_region=0;
- ret=region_compile(_feather, _mid->compile_mid, &region_hit_wraper, result, rule_num, thread_num);
- return ret;
-}
-
int Maat_set_scan_status(Maat_feather_t feather,scan_status_t* mid,enum MAAT_SCAN_OPT type,const void* value,int size)
{
struct _Maat_feather_t* _feather=(_Maat_feather_t*)feather;
@@ -2510,13 +2497,12 @@ int Maat_get_scan_status(Maat_feather_t feather, scan_status_t* mid, enum MAAT_S
struct _Maat_feather_t* _feather=(_Maat_feather_t*)feather;
struct _OUTER_scan_status_t* _mid=NULL;
struct Maat_hit_path_t* paths;
- struct Maat_hit_path_t condition;
- struct Maat_hierarchy_hit_path **path_inner=NULL;
- size_t n_read=0, i=0;
+
+ size_t n_read=0;
int ret=0;
_mid=grab_mid(mid, _feather, 0, 0);
- if(_mid->compile_mid==NULL)
+ if(_mid->compile_mid==NULL||_feather->scanner==NULL)
{
return 0;
}
@@ -2529,14 +2515,7 @@ int Maat_get_scan_status(Maat_feather_t feather, scan_status_t* mid, enum MAAT_S
}
paths=(struct Maat_hit_path_t*)value;
n_read=size/sizeof(struct Maat_hit_path_t);
- path_inner=ALLOC(struct Maat_hierarchy_hit_path*, n_read);
- Maat_hit_path_init(&condition);
- n_read=Maat_hierarchy_hit_path_select0(_mid->compile_mid, &condition, path_inner, n_read);
- for(i=0; i<n_read; i++)
- {
- paths[i]=path_inner[i]->path;
- }
- free(path_inner);
+ n_read=Maat_hierarchy_get_hit_paths(_feather->scanner->hier , _mid->compile_mid, paths, n_read);
ret=n_read;
break;
default: