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 "mem_pool.h"
21 #include "queue.h"
22 #include "hlist.h"
23 #include "pcb.h"
24 #include "spunge_mem.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /* Refresh time is 30 minutes */
31 #define FILLP_KEY_REFRESH_TIME 1800000000
32
33 #define SPUNGE_SOCKET_BOX_SIZE 1024
34
35
36 #define FILLP_FC_PREV_ADJUSTMENT_RATE_LOW_VAL 0.98
37 #define FILLP_FC_PREV_ADJUSTMENT_RATE_HIGH_VAL 1.02
38
39 /* fillp value to calcuate the send rate */
40 #define FILLP_FC_STABLESTATE_VAL_1 10
41
42 /* fillp value to calcuate the send rate */
43 #define FILLP_FC_STABLESTATE_VAL_2 5
44
45
46 /* fillp send rate multiple factor value */
47
48 #define FILLP_FC_SEND_RATE_MULTIPLE_FACTOR 0.95
49
50 /* fillp send rate value */
51 #define FILL_FC_SEND_RATE_TOTAL_1 1.5
52
53 /* fillp send rate value */
54 #define FILL_FC_SEND_RATE_TOTAL_2 1.05
55
56 /* fillp max rate limit value */
57 #define FILLP_FC_MAX_RATE_LIMIT_VAL 1000
58
59 /* FillP needs to calculate the fairness every 200 milliseconds */
60 #define SPUNGE_WEIGHT_ADJUST_INTERVAL 200000
61 #define SPUNGE_TOKEN_TIMER_MAX_INTERVAL 1000 /* 1 ms */
62
63 #define SPUNGE_TOKEN_TIMER_MAX_INTERVAL_RATE_ZERO SPUNGE_TOKEN_TIMER_MAX_INTERVAL
64
65 #define SPUNGE_TOKEN_MAX_BURST_TIME 10000 /* 10 ms */
66
67 #define SPUNGE_MAX_THREAD_NAME_LENGTH 16
68
69 FILLP_INT SpungeInstInit(struct SpungeInstance *inst);
70
71 void SpungeHandleMsgCycle(struct SpungeInstance *inst);
72
73 void SpungeFreeAcceptBox(struct FtSocket *sock);
74 void SpungeIncFreeCntPostEagain(struct FtSocket *sock);
75
76 void SpungeFreeSock(struct FtSocket *sock);
77
78 void SpungeInstanceMainThread(void *p);
79 void SpungePushRecvdDataToStack(void *arg);
80
81 void SpungeDestroySockTable(struct FtSocketTable *table);
82 struct FtSocketTable *SpungeCreateSockTable(FILLP_UINT maxSock);
83
84
SockOsListEntry(struct HlistNode * node)85 static __inline struct SockOsSocket *SockOsListEntry(struct HlistNode *node)
86 {
87 return (struct SockOsSocket *)((char *)(node) - (uintptr_t)(&(((struct SockOsSocket *)0)->osListNode)));
88 }
89
90 void FillpServerRecvRateAdjustment(struct SpungeInstance *inst, FILLP_UINT32 calcRecvTotalRate, FILLP_INT realRecvConn,
91 FILLP_UINT32 *connRecvCalLimit);
92
93 void FillpServerSendRateAdjustment(struct SpungeInstance *inst, FILLP_UINT32 calcSendTotalRate, FILLP_INT realSendConn,
94 FILLP_UINT32 *connSendCalLimit);
95
96
97 /* Implementing Fair Bandwidth sharing among sockets */
98 void FillpCalculateFairness(struct SpungeInstance *inst);
99
100 FILLP_BOOL FillpKillCore(void);
101
102 void FillpCheckPcbNackListToSend(void *args);
103
104 void SpinstLoopFairnessChecker(void *p);
105
106 void SpinstLoopMacTimerChecker(void *p);
107
108 void FtGlobalTimerInit(struct SpungeInstance *inst);
109
110 void SpungeDestroyInstance(struct SpungeInstance *inst);
111
112 void SpungeInitTokenBucket(struct SpungeInstance *inst);
113 void SpungeEnableTokenTimer(struct SpungeTokenBucke *stb);
114 void SpungeDisableTokenTimer(struct SpungeTokenBucke *stb);
115 void SpungeTokenTimerCb(void *p);
116 FILLP_INT SpungeItemRouteByToken(struct FillpPcbItem *item, struct FillpPcb *fpcb);
117 void SpungeCheckItemWaitTokenList(struct SpungeTokenBucke *stb);
118 void SpungeTokenBucketAddFpcb(struct FillpPcb *fpcb);
119 void SpungeTokenBucketDelFpcb(struct FillpPcb *fpcb);
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125
126 #endif /* SPUNGE_CORE_H */
127