Skip to content

Commit 7c7c84c

Browse files
committed
move set_selector
Signed-off-by: Hoooao <hao021014@163.com>
1 parent 31be1c8 commit 7c7c84c

File tree

5 files changed

+20
-28
lines changed

5 files changed

+20
-28
lines changed

include/bm/bm_sim/action_profile.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,6 @@ class ActionProfile : public NamedP4Object {
297297

298298
bool group_is_empty(grp_hdl_t grp) const;
299299

300-
bool is_selector_fanout_enabled() const {
301-
return selector_fanout_enabled;
302-
}
303-
304300
const ActionEntry &lookup(const Packet &pkt,
305301
const IndirectIndex &index) const;
306302

@@ -317,7 +313,6 @@ class ActionProfile : public NamedP4Object {
317313
std::shared_ptr<GroupSelectionIface> grp_selector_{nullptr};
318314
GroupSelectionIface *grp_selector{&grp_mgr};
319315
std::unique_ptr<Calculation> hash{nullptr};
320-
bool selector_fanout_enabled{false};
321316
};
322317

323318
} // namespace bm

include/bm/bm_sim/fanout_pkt_mgr.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,39 @@ class FanoutPktMgr {
7070
return instance_;
7171
}
7272

73-
inline void register_thread(std::thread::id thread_id,
74-
const std::function<void(const bm::Packet *)> &buffer_push_fn) {
75-
BMLOG_DEBUG("Registering thread {}", thread_id);
76-
fanout_ctx_map.emplace(thread_id, FanoutCtx(buffer_push_fn));
77-
}
78-
inline SelectorIface* get_grp_selector() {
79-
return grp_selector;
80-
}
81-
8273
FanoutCtx& get_fanout_ctx();
8374
void set_ctx(MatchTableIndirect *table, const Packet &pkt,
8475
ActionProfile *action_profile, bool hit);
8576
void reset_ctx();
8677
void replicate_for_entries(const std::vector<const ActionEntry*> &entries);
8778

79+
// PI overwrite selector specified during P4Object init,
80+
// so we need to set the selector in switch start_and_return_
81+
void set_grp_selector() {
82+
for (const auto &ap : act_profs) {
83+
ap->set_group_selector(grp_selector);
84+
}
85+
}
86+
inline void register_thread(std::thread::id thread_id,
87+
const std::function<void(const bm::Packet *)> &buffer_push_fn) {
88+
BMLOG_DEBUG("Registering thread {}", thread_id);
89+
fanout_ctx_map.emplace(thread_id, FanoutCtx(buffer_push_fn));
90+
}
91+
92+
// TODO(Hao): deduplicate packets fanout, optional
8893
#ifdef BM_PKT_FANOUT_ON
8994
static constexpr bool pkt_fanout_on = true;
9095
#else
9196
static constexpr bool pkt_fanout_on = false;
9297
#endif
9398
std::mutex fanout_pkt_mutex;
94-
// TODO(Hao): deduplicate packets fanout, optional
95-
96-
99+
std::vector<ActionProfile*> act_profs;
100+
97101
private:
98102
FanoutPktMgr() = default;
99103
std::unordered_map<std::thread::id, FanoutCtx> fanout_ctx_map;
100-
FanoutPktSelection fanout_selection;
101-
SelectorIface* grp_selector{&fanout_selection};
104+
std::shared_ptr<SelectorIface>
105+
grp_selector{std::make_shared<FanoutPktSelection>()};
102106
};
103107

104108
} // namespace bm

src/bm_sim/P4Objects.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,7 @@ P4Objects::init_pipelines(const Json::Value &cfg_root,
16591659
if (with_selection) {
16601660
if (is_selector_fanout(cfg_act_prof["selector"])) {
16611661
action_profile->set_selector_fanout();
1662+
FanoutPktMgr::instance().act_profs.push_back(action_profile.get());
16621663
} else {
16631664
auto calc = process_cfg_selector(cfg_act_prof["selector"]);
16641665
action_profile->set_hash(std::move(calc));

src/bm_sim/action_profile.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,18 +638,9 @@ ActionProfile::ref_count_decrease(const IndirectIndex &index) {
638638

639639
ActionProfile::mbr_hdl_t
640640
ActionProfile::choose_from_group(grp_hdl_t grp, const Packet &pkt) const {
641-
// TODO(Hao): PI resets to it own grp_selector, might be a bug, so I just sets
642-
// here for now..
643-
if (FanoutPktMgr::pkt_fanout_on && selector_fanout_enabled) {
644-
return FanoutPktMgr::instance().get_grp_selector()->get_from_hash(grp, 0);
645-
}
646641
if (!hash) return grp_selector->get_from_hash(grp, 0);
647642
hash_t h = static_cast<hash_t>(hash->output(pkt));
648643
return grp_selector->get_from_hash(grp, h);
649644
}
650645

651-
void ActionProfile::set_selector_fanout() {
652-
selector_fanout_enabled = true;
653-
}
654-
655646
} // namespace bm

targets/simple_switch/simple_switch.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ void
279279
SimpleSwitch::start_and_return_() {
280280
check_queueing_metadata();
281281
if (FanoutPktMgr::pkt_fanout_on) {
282+
FanoutPktMgr::instance().set_grp_selector();
282283
auto ingress_thread = std::thread(&SimpleSwitch::ingress_thread, this);
283284
FanoutPktMgr::instance().register_thread(
284285
ingress_thread.get_id(), [&](const bm::Packet *pkt) {

0 commit comments

Comments
 (0)