Skip to content

Commit

Permalink
sync k2 header with header in runtime light (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
astrophysik authored Jul 5, 2024
1 parent 2022e07 commit 2ac1018
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 8 deletions.
5 changes: 4 additions & 1 deletion compiler/code-gen/files/init-scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ void ComponentInfoFile::compile(CodeGenerator &W) const {
<< "static ImageInfo imageInfo {\"" << G->settings().k2_component_name.get() << "\"" << ","
<< std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() << ","
<< "K2_PLATFORM_HEADER_H_VERSION, "
<< "{" << "}};" << NL //todo:k2 add commit hash
<< "{}," //todo:k2 add commit hash
<< "{}," //todo:k2 add compiler hash?
<< (G->settings().k2_component_is_oneshot.get() ? "1" : "0")
<< "};" << NL
<< "return &imageInfo;" << NL
<< END;
W << CloseFile();
Expand Down
12 changes: 12 additions & 0 deletions compiler/compiler-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ void CompilerSettings::init() {
}
}
link_file.value_ = get_full_path(link_file.get());
if (functions_file.value_.empty()) {
if (mode.get() == "k2-component") {
functions_file.value_ = kphp_src_path.get() + "/builtin-functions/kphp-light/functions.txt";
} else {
functions_file.value_ = kphp_src_path.get() + "/builtin-functions/kphp-full/_functions.txt";
}
}
functions_file.value_ = get_full_path(functions_file.get());

if (k2_component_name.get() != "KPHP" || k2_component_is_oneshot.get()) {
kphp_error(mode.get() == "k2-component", "Options \"k2-component-name\" and \"oneshot\" available only fore k2-component mode");
}

if (mode.get() == "lib") {
if (!tl_schema_file.get().empty()) {
Expand Down
2 changes: 2 additions & 0 deletions compiler/compiler-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class CompilerSettings : vk::not_copyable {
KphpOption<std::string> php_code_version;
KphpOption<std::string> k2_component_name;

KphpOption<bool> k2_component_is_oneshot;

KphpOption<std::string> cxx;
KphpOption<std::string> cxx_toolchain_dir;
KphpOption<std::string> extra_cxx_flags;
Expand Down
4 changes: 3 additions & 1 deletion compiler/kphp2cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ int main(int argc, char *argv[]) {
parser.add("Path to kphp source", settings->kphp_src_path,
's', "source-path", "KPHP_PATH", get_default_kphp_path());
parser.add("Internal file with the list of supported PHP functions", settings->functions_file,
'f', "functions-file", "KPHP_FUNCTIONS", "${KPHP_PATH}/builtin-functions/kphp-full/_functions.txt");
'f', "functions-file", "KPHP_FUNCTIONS");
parser.add("File with kphp runtime sha256 hash", settings->runtime_sha256_file,
"runtime-sha256", "KPHP_RUNTIME_SHA256", "${KPHP_PATH}/objs/php_lib_version.sha256");
parser.add("The output binary type: server, k2-component, cli or lib", settings->mode,
Expand Down Expand Up @@ -295,6 +295,8 @@ int main(int argc, char *argv[]) {
"require-class-typing", "KPHP_REQUIRE_CLASS_TYPING");
parser.add("Define k2 component name. Default is \"KPHP\"", settings->k2_component_name,
"k2-component-name", "KPHP_K2_COMPONENT_NAME", "KPHP");
parser.add("Enable oneshot mode to k2 component", settings->k2_component_is_oneshot,
"oneshot", "KPHP_K2_COMPONENT_IS_ONESHOT");

parser.add_implicit_option("Linker flags", settings->ld_flags);
parser.add_implicit_option("Incremental linker flags", settings->incremental_linker_flags);
Expand Down
14 changes: 9 additions & 5 deletions runtime-light/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <stdint.h>
#endif

#define K2_PLATFORM_HEADER_H_VERSION 5
#define K2_PLATFORM_HEADER_H_VERSION 6

// Always check that enum value is a valid value!

Expand Down Expand Up @@ -94,7 +94,7 @@ struct PlatformCtx {

/*
* Immediately abort component execution.
* Function is [[noreturn]]
* Function is `[[noreturn]]`
*/
void (*abort)();

Expand Down Expand Up @@ -210,7 +210,7 @@ struct PlatformCtx {
* If a component has not read all updates during a `poll` iteration, the
* platform is guaranteed to reschedule it.
*/
char (*take_update)(uint64_t *update_d);
uint8_t (*take_update)(uint64_t *update_d);
/*
* Only utf-8 string supported.
* Possible `level` values:
Expand Down Expand Up @@ -241,9 +241,9 @@ enum PollStatus {
PollBlocked = 0,
// there is some cpu work to do; platform will reschedule component
PollReschedule = 1,
// component decide to shutdown
// component decide to shutdown normally
PollFinishedOk = 2,
// component decide to shutdown
// component decide to shutdown unexpectedly
PollFinishedError = 3,
};

Expand All @@ -255,6 +255,10 @@ struct ImageInfo {
uint64_t build_timestamp;
uint64_t header_h_version;
uint8_t commit_hash[40];
// TODO: more informative?
uint8_t compiler_hash[64];
// bool
uint8_t is_oneshot;
};

// Every image should provide these symbols
Expand Down
2 changes: 1 addition & 1 deletion runtime-light/stdlib/string-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void f$debug_print_string(const string &s) {
Optional<int64_t> f$byte_to_int(const string &s) {
if (s.size() != 1) {
php_warning("Cannot convert non-byte string to int");
return false;
return Optional<int64_t>();
}
return *s.c_str();
}
Expand Down
3 changes: 3 additions & 0 deletions tests/k2-components/oom_loop.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

$str = "aabb";
$id = 0;

while(true) {
$big_string = $big_string . $big_string;
$big_string[3] = strval($id);
$id++;
}

0 comments on commit 2ac1018

Please sign in to comment.