1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef SPUNGE_CORE_H
17 #define SPUNGE_CORE_H
18 #include "fillpinc.h"
19 #include "spunge.h"
20 #include "lf_ring.h"
21 #include "queue.h"
22 #include "log.h"
23 #include "hlist.h"
24 #include "pcb.h"
25 #include "spunge_mem.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /* Refresh time is 30 minutes */
32 #define FILLP_KEY_REFRESH_TIME 1800000000
33
34 #define SPUNGE_SOCKET_BOX_SIZE 1024
35
36
37 #define FILLP_FC_PREV_ADJUSTMENT_RATE_LOW_VAL 0.98
38 #define FILLP_FC_PREV_ADJUSTMENT_RATE_HIGH_VAL 1.02
39
40 /* fillp value to calcuate the send rate */
41 #define FILLP_FC_STABLESTATE_VAL_1 10
42
43 /* fillp value to calcuate the send rate */
44 #define FILLP_FC_STABLESTATE_VAL_2 5
45
46
47 /* fillp send rate multiple factor value */
48
49 #define FILLP_FC_SEND_RATE_MULTIPLE_FACTOR 0.95
50
51 /* fillp send rate value */
52 #define FILL_FC_SEND_RATE_TOTAL_1 1.5
53
54 /* fillp send rate value */
55 #define FILL_FC_SEND_RATE_TOTAL_2 1.05
56
57 /* fillp max rate limit value */
58 #define FILLP_FC_MAX_RATE_LIMIT_VAL 1000
59
60 /* FillP needs to calculate the fairness every 200 milliseconds */
61 #define SPUNGE_WEIGHT_ADJUST_INTERVAL 200000
62 #define SPUNGE_TOKEN_TIMER_MAX_INTERVAL 1000 /* 1 ms */
63
64 #define SPUNGE_TOKEN_TIMER_MAX_INTERVAL_RATE_ZERO SPUNGE_TOKEN_TIMER_MAX_INTERVAL
65
66 #define SPUNGE_TOKEN_MAX_BURST_TIME 10000 /* 10 ms */
67
68 #define SPUNGE_MAX_THREAD_NAME_LENGTH 16
69
70 FILLP_INT SpungeInstInit(struct SpungeInstance *inst);
71
72 void SpungeHandleMsgCycle(struct SpungeInstance *inst);
73
74 void SpungeFreeAcceptBox(struct FtSocket *sock);
75 void SpungeIncFreeCntPostEagain(struct FtSocket *sock);
76
77 void SpungeFreeSock(struct FtSocket *sock);
78
79 void SpungeInstanceMainThread(void *p);
80 void SpungePushRecvdDataToStack(void *arg);
81
82 void SpungeDestroySockTable(struct FtSocketTable *table);
83 struct FtSocketTable *SpungeCreateSockTable(FILLP_UINT maxSock);
84
85
SockOsListEntry(struct HlistNode * node)86 static __inline struct SockOsSocket *SockOsListEntry(struct HlistNode *node)
87 {
88 return (struct SockOsSocket *)((char *)(node) - (uintptr_t)(&(((struct SockOsSocket *)0)->osListNode)));
89 }
90
91 void FillpServerRecvRateAdjustment(struct SpungeInstance *inst, FILLP_UINT32 calcRecvTotalRate, FILLP_INT realRecvConn,
92 FILLP_UINT32 *connRecvCalLimit);
93
94 void FillpServerSendRateAdjustment(struct SpungeInstance *inst, FILLP_UINT32 calcSendTotalRate, FILLP_INT realSendConn,
95 FILLP_UINT32 *connSendCalLimit);
96
97
98 /* Implementing Fair Bandwidth sharing among sockets */
99 void FillpCalculateFairness(struct SpungeInstance *inst);
100
101 FILLP_BOOL FillpKillCore(void);
102
103 void FillpCheckPcbNackListToSend(void *args);
104
105 void SpinstLoopFairnessChecker(void *p);
106
107 void SpinstLoopMacTimerChecker(void *p);
108
109 void FtGlobalTimerInit(struct SpungeInstance *inst);
110
111 void SpungeDestroyInstance(struct SpungeInstance *inst);
112
113 void SpungeInitTokenBucket(struct SpungeInstance *inst);
114 void SpungeEnableTokenTimer(struct SpungeTokenBucke *stb);
115 void SpungeDisableTokenTimer(struct SpungeTokenBucke *stb);
116 void SpungeTokenTimerCb(void *p);
117 FILLP_INT SpungeItemRouteByToken(struct FillpPcbItem *item, struct FillpPcb *fpcb);
118 void SpungeCheckItemWaitTokenList(struct SpungeTokenBucke *stb);
119 void SpungeTokenBucketAddFpcb(struct FillpPcb *fpcb);
120 void SpungeTokenBucketDelFpcb(struct FillpPcb *fpcb);
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126
127 #endif /* SPUNGE_CORE_H */
128