-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create counter as an extern in psa * counters read and written correctly * remove unused file * support counter write in runtime_CLI * added liscense and counter reset * added psa namespace * patched runtime_CLI to better support counter writes * mark counter_arrays as special * syntax, remove macro, counter_array not PSA_Counter should be hidden * style and renaming count primitive
- Loading branch information
1 parent
c39179f
commit 884e01b
Showing
9 changed files
with
236 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Copyright 2019-present Derek So | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* Derek So ([email protected]) | ||
* | ||
*/ | ||
|
||
|
||
#include "psa_counter.h" | ||
|
||
namespace bm { | ||
|
||
namespace psa { | ||
|
||
void | ||
PSA_Counter::count(const Data &index) { | ||
_counter->get_counter( | ||
index.get<size_t>()).increment_counter(get_packet()); | ||
} | ||
|
||
Counter & | ||
PSA_Counter::get_counter(size_t idx) { | ||
return _counter->get_counter(idx); | ||
} | ||
|
||
const Counter & | ||
PSA_Counter::get_counter(size_t idx) const { | ||
return _counter->get_counter(idx); | ||
} | ||
|
||
Counter::CounterErrorCode | ||
PSA_Counter::reset_counters(){ | ||
return _counter->reset_counters(); | ||
} | ||
|
||
BM_REGISTER_EXTERN_W_NAME(Counter, PSA_Counter); | ||
BM_REGISTER_EXTERN_W_NAME_METHOD(Counter, PSA_Counter, count, const Data &); | ||
|
||
} // namespace bm::psa | ||
|
||
} // namespace bm | ||
|
||
int import_counters(){ | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* Copyright 2019-present Derek So | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* Derek So ([email protected]) | ||
* | ||
*/ | ||
|
||
|
||
#ifndef PSA_SWITCH_PSA_COUNTER_H_ | ||
#define PSA_SWITCH_PSA_COUNTER_H_ | ||
|
||
#include <bm/bm_sim/extern.h> | ||
#include <bm/bm_sim/counters.h> | ||
|
||
namespace bm { | ||
|
||
namespace psa { | ||
|
||
class PSA_Counter : public bm::ExternType { | ||
public: | ||
static constexpr p4object_id_t spec_id = 0xffffffff; | ||
|
||
BM_EXTERN_ATTRIBUTES { | ||
BM_EXTERN_ATTRIBUTE_ADD(n_counters); | ||
BM_EXTERN_ATTRIBUTE_ADD(type); | ||
} | ||
|
||
void init() override { | ||
_counter = std::unique_ptr<CounterArray>( | ||
new CounterArray(get_name() + ".$impl", | ||
spec_id, | ||
n_counters.get<size_t>())); | ||
} | ||
|
||
void count(const Data &index); | ||
|
||
Counter &get_counter(size_t idx); | ||
|
||
const Counter &get_counter(size_t idx) const; | ||
|
||
Counter::CounterErrorCode reset_counters(); | ||
|
||
size_t size() const { return _counter->size(); }; | ||
|
||
private: | ||
Data n_counters; | ||
Data type; | ||
std::unique_ptr<CounterArray> _counter; | ||
}; | ||
|
||
} // namespace bm::psa | ||
|
||
} // namespace bm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters