Skip to content

Commit 11edfff

Browse files
authored
Merge pull request #1265 from AndreasAakesson/dev
Make CPU features optional
2 parents 0bb249e + e66a6bc commit 11edfff

16 files changed

Lines changed: 164 additions & 90 deletions

File tree

CMakeLists.txt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@ execute_process(COMMAND git describe --dirty
2323
OUTPUT_VARIABLE OS_VERSION)
2424
string(STRIP ${OS_VERSION} OS_VERSION)
2525

26+
option(cpu_feat_vanilla "Restrict use of CPU features to vanilla" ON)
27+
if(cpu_feat_vanilla)
28+
include("cmake/vanilla.cmake")
29+
set(DEFAULT_SETTINGS_CMAKE "vanilla.cmake") # for service cmake
30+
set(DEFAULT_VM "vm.vanilla.json") # vmrunner
31+
else()
32+
include("cmake/cpu_feat.cmake")
33+
set(DEFAULT_SETTINGS_CMAKE "cpu_feat.cmake") # for service cmake
34+
set(DEFAULT_VM "vm.cpu_feat.json") # vmrunner
35+
endif(cpu_feat_vanilla)
36+
2637
# create random hex string as stack protector canary
2738
string(RANDOM LENGTH 8 ALPHABET 0123456789ABCDEF STACK_PROTECTOR_VALUE)
2839

29-
set(CAPABS "-mavx -maes -mfma -fstack-protector-strong -D_STACK_GUARD_VALUE_=0x${STACK_PROTECTOR_VALUE} ")
40+
set(CAPABS "${CAPABS} -fstack-protector-strong -D_STACK_GUARD_VALUE_=0x${STACK_PROTECTOR_VALUE}")
3041

3142
# Various global defines
3243
# * NO_DEBUG disables output from the debug macro
@@ -160,10 +171,20 @@ endif(rapidjson)
160171
#
161172
# Installation
162173
#
163-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/etc/service.cmake DESTINATION includeos)
164-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/etc/library.cmake DESTINATION includeos)
165-
install(DIRECTORY vmrunner DESTINATION includeos/)
174+
175+
# Install cmake files
176+
install(FILES etc/service.cmake DESTINATION includeos)
177+
install(FILES etc/library.cmake DESTINATION includeos)
178+
install(FILES cmake/${DEFAULT_SETTINGS_CMAKE} DESTINATION includeos RENAME settings.cmake) # cpu_feat_vanilla opt
179+
180+
# Install vmrunner
181+
install(DIRECTORY vmrunner DESTINATION includeos)
182+
install(FILES vmrunner/${DEFAULT_VM} DESTINATION includeos/vmrunner/ RENAME vm.default.json) # cpu_feat_vanilla opt
183+
184+
# Install toolchain
166185
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/i686-elf-toolchain.cmake DESTINATION includeos)
186+
187+
# Install seed
167188
install(DIRECTORY seed/ DESTINATION includeos/seed)
168189

169190
# Install boot util

api/net/tcp/connection.hpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ class Connection : public std::enable_shared_from_this<Connection> {
6565
using WriteBuffer = Write_queue::WriteBuffer;
6666

6767
public:
68-
/** Called with the connection itself when it's been established. */
68+
/** Called with the connection itself when it's been established. May be a nullptr if the connection failed. */
6969
using ConnectCallback = delegate<void(Connection_ptr self)>;
7070
/**
7171
* @brief Event when a connection has been established.
7272
* This event lets you know when to start using the connection,
7373
* and should always be assigned.
74+
* NOTE: The Connection_ptr will be a nullptr when an outgoing connection failed.
7475
*
7576
* @param[in] callback The callback
7677
*
@@ -137,18 +138,6 @@ class Connection : public std::enable_shared_from_this<Connection> {
137138
*/
138139
inline Connection& on_write(WriteCallback callback);
139140

140-
/** Called with the error encountered. */
141-
using ErrorCallback = delegate<void(const TCPException& err)>;
142-
/**
143-
* @brief Event when a connection has experienced an error of any kind.
144-
* Pretty useless in it's current form, and only useful for printing.
145-
*
146-
* @param[in] callback The callback
147-
*
148-
* @return This connection
149-
*/
150-
inline Connection& on_error(ErrorCallback callback);
151-
152141
/** Called with the packet that got dropped and the reason why. */
153142
using PacketDroppedCallback = delegate<void(const Packet&, Drop_reason)>;
154143
/**
@@ -231,7 +220,10 @@ class Connection : public std::enable_shared_from_this<Connection> {
231220
*/
232221
Stream(Connection_ptr conn)
233222
: tcp{std::move(conn)}
234-
{}
223+
{
224+
// stream for a nullptr makes no sense
225+
Expects(tcp != nullptr);
226+
}
235227

236228
/**
237229
* @brief Event when the stream is connected/established/ready to use.
@@ -788,6 +780,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
788780
/**
789781
* @brief Open the connection.
790782
* Active determines whether the connection is active or passive.
783+
* May throw if no remote host, or state isnt valid for opening.
791784
*
792785
* @param[in] active Whether its an active (outgoing) or passive (listening)
793786
*/
@@ -843,7 +836,6 @@ class Connection : public std::enable_shared_from_this<Connection> {
843836
/** Callbacks */
844837
ConnectCallback on_connect_;
845838
DisconnectCallback on_disconnect_;
846-
ErrorCallback on_error_;
847839
PacketDroppedCallback on_packet_dropped_;
848840
RtxTimeoutCallback on_rtx_timeout_;
849841
CloseCallback on_close_;
@@ -998,15 +990,15 @@ class Connection : public std::enable_shared_from_this<Connection> {
998990
/*
999991
Invoke/signal the diffrent TCP events.
1000992
*/
1001-
void signal_connect()
1002-
{ if(on_connect_) on_connect_(shared_from_this()); }
993+
void signal_connect(const bool success = true)
994+
{
995+
if(on_connect_)
996+
(success) ? on_connect_(shared_from_this()) : on_connect_(nullptr);
997+
}
1003998

1004999
void signal_disconnect(Disconnect::Reason&& reason)
10051000
{ on_disconnect_(shared_from_this(), Disconnect{reason}); }
10061001

1007-
void signal_error(TCPException error)
1008-
{ if(on_error_) on_error_(std::forward<TCPException>(error)); }
1009-
10101002
void signal_packet_dropped(const Packet& packet, Drop_reason reason)
10111003
{ if(on_packet_dropped_) on_packet_dropped_(packet, reason); }
10121004

@@ -1264,7 +1256,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
12641256
Retransmission timeout limit reached
12651257
*/
12661258
bool rto_limit_reached() const
1267-
{ return rtx_attempt_ >= 15 or syn_rtx_ >= 5; };
1259+
{ return rtx_attempt_ >= 14 or syn_rtx_ >= 4; };
12681260

12691261
/*
12701262
Remove all packets acknowledge by ACK in retransmission queue

api/net/tcp/connection.inc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ inline Connection& Connection::on_write(WriteCallback cb) {
2424
return *this;
2525
}
2626

27-
inline Connection& Connection::on_error(ErrorCallback callback) {
28-
on_error_ = callback;
29-
return *this;
30-
}
31-
3227
inline Connection& Connection::on_packet_dropped(PacketDroppedCallback callback) {
3328
on_packet_dropped_ = callback;
3429
return *this;

cmake/cpu_feat.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(CAPABS "-mavx -maes -mfma")
2+
message(STATUS "Using extended CPU features: AVX, AES, FMA. CAPABS = ${CAPABS}")

cmake/vanilla.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(CAPABS "-msse3")
2+
message(STATUS "Using vanilla CPU features: SSE3. CAPABS = ${CAPABS}")

etc/library.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ endif(CMAKE_COMPILER_IS_GNUCC)
1717
set(CMAKE_ASM_NASM_OBJECT_FORMAT "elf")
1818
enable_language(ASM_NASM)
1919

20+
# defines $CAPABS depending on installation
21+
include(${CMAKE_CURRENT_LIST_DIR}/settings.cmake)
22+
2023
# Various global defines
2124
# * OS_TERMINATE_ON_CONTRACT_VIOLATION provides classic assert-like output from Expects / Ensures
2225
# * _GNU_SOURCE enables POSIX-extensions in newlib, such as strnlen. ("everything newlib has", ref. cdefs.h)
23-
set(CAPABS "-msse3 -fstack-protector-strong -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE")
26+
set(CAPABS "${CAPABS} -fstack-protector-strong -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE")
2427
set(WARNS "-Wall -Wextra") #-pedantic
2528

2629
# configure options

etc/service.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ endif(CMAKE_COMPILER_IS_GNUCC)
2525
set(CMAKE_ASM_NASM_OBJECT_FORMAT "elf")
2626
enable_language(ASM_NASM)
2727

28-
set(CAPABS "-mavx -maes -mfma -fstack-protector-strong")
28+
# defines $CAPABS depending on installation
29+
include(${CMAKE_CURRENT_LIST_DIR}/settings.cmake)
2930

3031
# Various global defines
3132
# * OS_TERMINATE_ON_CONTRACT_VIOLATION provides classic assert-like output from Expects / Ensures
3233
# * _GNU_SOURCE enables POSIX-extensions in newlib, such as strnlen. ("everything newlib has", ref. cdefs.h)
33-
set(CAPABS "${CAPABS} -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE -DSERVICE=\"\\\"${BINARY}\\\"\" -DSERVICE_NAME=\"\\\"${SERVICE_NAME}\\\"\"")
34+
set(CAPABS "${CAPABS} -fstack-protector-strong -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE -DSERVICE=\"\\\"${BINARY}\\\"\" -DSERVICE_NAME=\"\\\"${SERVICE_NAME}\\\"\"")
3435
set(WARNS "-Wall -Wextra") #-pedantic
3536

3637
# configure options

src/arch/x86/start.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ rock_bottom:
5050
;; enable SSE before we enter C/C++ land
5151
call enable_sse
5252
;; ... and XSAVE to get xsetbv/xgetbv working
53-
call enable_xsave
53+
;call enable_xsave
5454
;; ... and finally, enable AVX
55-
call enable_avx
55+
;call enable_avx
5656

5757
;; Place multiboot parameters on stack
5858
push ebx

src/net/tcp/connection.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ void Connection::reset_callbacks()
8282
on_disconnect_ = {this, &Connection::default_on_disconnect};
8383
on_connect_.reset();
8484
writeq.on_write(nullptr);
85-
on_error_.reset();
8685
on_packet_dropped_.reset();
8786
on_rtx_timeout_.reset();
8887
on_close_.reset();
@@ -246,16 +245,10 @@ void Connection::writeq_reset() {
246245
rtx_timer.stop();
247246
}
248247

249-
void Connection::open(bool active) {
250-
try {
251-
debug("<TCP::Connection::open> Trying to open Connection...\n");
252-
state_->open(*this, active);
253-
}
254-
// No remote host, or state isnt valid for opening.
255-
catch (const TCPException& e) {
256-
debug("<TCP::Connection::open> Cannot open Connection. \n");
257-
signal_error(e);
258-
}
248+
void Connection::open(bool active)
249+
{
250+
debug("<TCP::Connection::open> Trying to open Connection...\n");
251+
state_->open(*this, active);
259252
}
260253

261254
void Connection::close() {
@@ -269,8 +262,9 @@ void Connection::close() {
269262
if(is_state(Closed::instance()))
270263
signal_close();
271264
}
272-
catch(const TCPException& err) {
273-
signal_error(err);
265+
catch(const TCPException&) {
266+
// just ignore for now, it's kinda stupid its even throwing (i think)
267+
// early return is_closing will probably prevent this from happening
274268
}
275269
}
276270

@@ -685,7 +679,7 @@ void Connection::retransmit() {
685679
writeq.size(), buf.length() - buf.acknowledged);
686680
fill_packet(*packet, buf.data() + writeq.acked(), buf.length() - writeq.acked());
687681
}
688-
682+
rtx_attempt_++;
689683
packet->set_seq(cb.SND.UNA);
690684

691685
/*
@@ -766,16 +760,11 @@ void Connection::rtx_timeout() {
766760
}
767761

768762
// retransmit SND.UNA
769-
retransmit();
763+
retransmit(); // increases rtx_attempt
764+
765+
// "back off" timer
766+
rttm.RTO *= 2.0;
770767

771-
if(cb.SND.UNA != cb.ISS) {
772-
// "back off" timer
773-
rttm.RTO *= 2.0;
774-
}
775-
// we never queue SYN packets since they don't carry data..
776-
else {
777-
rttm.RTO = std::chrono::seconds(3);
778-
}
779768
// timer need to be restarted
780769
rtx_start();
781770

@@ -789,7 +778,7 @@ void Connection::rtx_timeout() {
789778
790779
ssthresh = max (FlightSize / 2, 2*SMSS)
791780
*/
792-
if(rtx_attempt_++ == 0)
781+
if(rtx_attempt_ == 1)
793782
{
794783
// RFC 4015
795784
/*
@@ -888,14 +877,13 @@ void Connection::clean_up() {
888877

889878
on_connect_.reset();
890879
on_disconnect_.reset();
891-
on_error_.reset();
892880
on_packet_dropped_.reset();
893881
on_rtx_timeout_.reset();
894882
on_close_.reset();
895883
read_request.clean_up();
896884
_on_cleanup_.reset();
897885

898-
debug("<Connection::clean_up> Succesfully cleaned up %s\n", to_string().c_str());
886+
debug2("<Connection::clean_up> Succesfully cleaned up %s\n", to_string().c_str());
899887
}
900888

901889
std::string Connection::TCB::to_string() const {

src/net/tcp/connection_states.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ State::Result Connection::SynSent::handle(Connection& tcp, Packet_ptr in) {
890890
// 2. check RST
891891
if(UNLIKELY(in->isset(RST))) {
892892
if(in->isset(ACK)) {
893-
tcp.signal_error(TCPException{"Connection reset."});
893+
tcp.signal_connect(false);
894894
tcp.drop(*in, Drop_reason::RST);
895895
return CLOSED;
896896
} else {
@@ -960,6 +960,13 @@ State::Result Connection::SynSent::handle(Connection& tcp, Packet_ptr in) {
960960
tcb.SND.WL2 = in->ack();
961961
// end of correction
962962

963+
// [RFC 6298] p.4 (5.7)
964+
if(UNLIKELY(tcp.syn_rtx_ > 0))
965+
{
966+
tcp.syn_rtx_ = 0;
967+
tcp.rttm.RTO = RTTM::seconds(3.0);
968+
}
969+
963970
tcp.set_state(Connection::Established::instance());
964971
const seq_t snd_nxt = tcb.SND.NXT;
965972
tcp.signal_connect(); // NOTE: User callback
@@ -1061,6 +1068,13 @@ State::Result Connection::SynReceived::handle(Connection& tcp, Packet_ptr in) {
10611068

10621069
tcp.handle_ack(*in);
10631070

1071+
// [RFC 6298] p.4 (5.7)
1072+
if(UNLIKELY(tcp.syn_rtx_ > 0))
1073+
{
1074+
tcp.syn_rtx_ = 0;
1075+
tcp.rttm.RTO = RTTM::seconds(3.0);
1076+
}
1077+
10641078
tcp.signal_connect(); // NOTE: User callback
10651079

10661080
// 7. proccess the segment text

0 commit comments

Comments
 (0)