| 1089 | } |
| 1090 | |
| 1091 | void |
| 1092 | tcp_init(void) |
| 1093 | { |
| 1094 | const char *tcbhash_tuneable; |
| 1095 | int hashsize; |
| 1096 | |
| 1097 | tcbhash_tuneable = "net.inet.tcp.tcbhashsize"; |
| 1098 | |
| 1099 | #ifdef TCP_HHOOK |
| 1100 | if (hhook_head_register(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN, |
| 1101 | &V_tcp_hhh[HHOOK_TCP_EST_IN], HHOOK_NOWAIT|HHOOK_HEADISINVNET) != 0) |
| 1102 | printf("%s: WARNING: unable to register helper hook\n", __func__); |
| 1103 | if (hhook_head_register(HHOOK_TYPE_TCP, HHOOK_TCP_EST_OUT, |
| 1104 | &V_tcp_hhh[HHOOK_TCP_EST_OUT], HHOOK_NOWAIT|HHOOK_HEADISINVNET) != 0) |
| 1105 | printf("%s: WARNING: unable to register helper hook\n", __func__); |
| 1106 | #endif |
| 1107 | #ifdef STATS |
| 1108 | if (tcp_stats_init()) |
| 1109 | printf("%s: WARNING: unable to initialise TCP stats\n", |
| 1110 | __func__); |
| 1111 | #endif |
| 1112 | hashsize = TCBHASHSIZE; |
| 1113 | TUNABLE_INT_FETCH(tcbhash_tuneable, &hashsize); |
| 1114 | if (hashsize == 0) { |
| 1115 | /* |
| 1116 | * Auto tune the hash size based on maxsockets. |
| 1117 | * A perfect hash would have a 1:1 mapping |
| 1118 | * (hashsize = maxsockets) however it's been |
| 1119 | * suggested that O(2) average is better. |
| 1120 | */ |
| 1121 | hashsize = maketcp_hashsize(maxsockets / 4); |
| 1122 | /* |
| 1123 | * Our historical default is 512, |
| 1124 | * do not autotune lower than this. |
| 1125 | */ |
| 1126 | if (hashsize < 512) |
| 1127 | hashsize = 512; |
| 1128 | if (bootverbose && IS_DEFAULT_VNET(curvnet)) |
| 1129 | printf("%s: %s auto tuned to %d\n", __func__, |
| 1130 | tcbhash_tuneable, hashsize); |
| 1131 | } |
| 1132 | /* |
| 1133 | * We require a hashsize to be a power of two. |
| 1134 | * Previously if it was not a power of two we would just reset it |
| 1135 | * back to 512, which could be a nasty surprise if you did not notice |
| 1136 | * the error message. |
| 1137 | * Instead what we do is clip it to the closest power of two lower |
| 1138 | * than the specified hash value. |
| 1139 | */ |
| 1140 | if (!powerof2(hashsize)) { |
| 1141 | int oldhashsize = hashsize; |
| 1142 | |
| 1143 | hashsize = maketcp_hashsize(hashsize); |
| 1144 | /* prevent absurdly low value */ |
| 1145 | if (hashsize < 16) |
| 1146 | hashsize = 16; |
| 1147 | printf("%s: WARNING: TCB hash size not a power of 2, " |
| 1148 | "clipped from %d to %d.\n", __func__, oldhashsize, |
nothing calls this directly
no test coverage detected