Skip to content

Commit

Permalink
lkl: add LKL_HIJACK_BOOT_CMDLINE option to configure boot cmdline
Browse files Browse the repository at this point in the history
This patch changes the API of lkl_start_kernel().  The memsize parameter
is now able to specify via this env variable with "mem=100M" string.

Also this patch includes 2 API incompatibility.

1. lkl_start_kernel() now doesn't have memsize argument
2. LKL_HIJACK_NET_IP=dhcp is now obsolted - use ip=dhpc in
LKL_HIJACK_BOOT_CMDLINE instead.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
  • Loading branch information
thehajime committed Feb 10, 2017
1 parent 45caa74 commit bc3fe96
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
14 changes: 12 additions & 2 deletions Documentation/lkl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ are the list of those variable for your environment.
$ LKL_HIJACK_NET_IP=198.51.100.5 lkl-hijack.sh ip address show
```

Additionally, DHCP is experimentally available with the following syntax.
If you want to use DHCP for the IP address assignment, use
LKL_HIJACK_BOOT_CMDLINE with "ip=dhcp" option.
```
$ LKL_HIJACK_NET_IP=dhcp LKL_HIJACK_NET_IFTYPE=tap LKL_HIJACK_NET_IFPARAMS=tap0 lkl-hijack.sh ip address show
$ LKL_HIJACK_BOOT_CMDLINE="ip=dhcp" LKL_HIJACK_NET_IFTYPE=tap \
LKL_HIJACK_NET_IFPARAMS=tap0 lkl-hijack.sh ip address
```

* LKL_HIJACK_NET_NETMASK_LEN
Expand Down Expand Up @@ -246,6 +248,14 @@ are the list of those variable for your environment.
$ LKL_HIJACK_SYSCTL="net.ipv4.tcp_wmem=4096 87380 2147483647"
./bin/lkl-hijack.sh ip address show
```
* LKL_HIJACK_BOOT_CMDLINE

Specify the command line to the kernel boot so that change the configuration
on a kernel instance. For instance, you can change the memory size with
below.
```
$ LKL_HIJACK_BOOT_CMDLINE="mem=1G" LKL_HIJACK_DEBUG=1 lkl-hijack.sh ip add
```

FAQ
===
Expand Down
2 changes: 0 additions & 2 deletions arch/lkl/include/uapi/asm/host_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@ struct lkl_host_operations {
* The function returns only after the kernel is shutdown with lkl_sys_halt.
*
* @lkl_ops - pointer to host operations
* @mem_size - how much memory to allocate to the Linux kernel
* @cmd_line - format for command line string that is going to be used to
* generate the Linux kernel command line
*/
int lkl_start_kernel(struct lkl_host_operations *lkl_ops,
unsigned long mem_size,
const char *cmd_line, ...);

/**
Expand Down
12 changes: 9 additions & 3 deletions arch/lkl/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,26 @@ static char cmd_line[COMMAND_LINE_SIZE];
static void *init_sem;
static int is_running;
void (*pm_power_off)(void) = NULL;
static unsigned long mem_size;
static unsigned long mem_size = 64 * 1024 * 1024;

long lkl_panic_blink(int state)
{
lkl_ops->panic();
return 0;
}

static int __init setup_mem_size(char *str)
{
mem_size = memparse(str, NULL);
return 0;
}
early_param("mem", setup_mem_size);

void __init setup_arch(char **cl)
{
*cl = cmd_line;
panic_blink = lkl_panic_blink;
parse_early_param();
bootmem_init(mem_size);
}

Expand All @@ -41,14 +49,12 @@ static void __init lkl_run_kernel(void *arg)
}

int __init lkl_start_kernel(struct lkl_host_operations *ops,
unsigned long _mem_size,
const char *fmt, ...)
{
va_list ap;
int ret;

lkl_ops = ops;
mem_size = _mem_size;

va_start(ap, fmt);
ret = vsnprintf(boot_command_line, COMMAND_LINE_SIZE, fmt, ap);
Expand Down
2 changes: 1 addition & 1 deletion tools/lkl/cptofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ int main(int argc, char **argv)
}
disk_id = ret;

lkl_start_kernel(&lkl_host_ops, 100 * 1024 * 1024, "");
lkl_start_kernel(&lkl_host_ops, "mem=100M");

ret = lkl_mount_dev(disk_id, cla.part, cla.fsimg_type,
cptofs ? 0 : LKL_MS_RDONLY,
Expand Down
2 changes: 1 addition & 1 deletion tools/lkl/fs2tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ int main(int argc, char **argv)
}
disk_id = ret;

lkl_start_kernel(&lkl_host_ops, 10 * 1024 * 1024, "");
lkl_start_kernel(&lkl_host_ops, "mem=10M");

ret = lkl_mount_dev(disk_id, cla.part, cla.fsimg_type, LKL_MS_RDONLY,
NULL, mpoint, sizeof(mpoint));
Expand Down
8 changes: 2 additions & 6 deletions tools/lkl/lib/hijack/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ hijack_init(void)
cpu_set_t ori_cpu;
char *offload1 = getenv("LKL_HIJACK_OFFLOAD");
int offload = 0;
char boot_cmdline[256] = "\0";
char *sysctls = getenv("LKL_HIJACK_SYSCTL");
char *boot_cmdline = getenv("LKL_HIJACK_BOOT_CMDLINE") ? : "";

memset(&nd_args, 0, sizeof(struct lkl_netdev_args));
if (!debug) {
Expand Down Expand Up @@ -326,11 +326,7 @@ hijack_init(void)
if (single_cpu_mode == 1)
PinToFirstCpu(&ori_cpu);

/* set cmdline if dhcp case */
if ((ip && !strcmp(ip, "dhcp")) && (nd_id != -1))
snprintf(boot_cmdline, sizeof(boot_cmdline), "ip=dhcp");

ret = lkl_start_kernel(&lkl_host_ops, 64 * 1024 * 1024UL, boot_cmdline);
ret = lkl_start_kernel(&lkl_host_ops, boot_cmdline);
if (ret) {
fprintf(stderr, "can't start kernel: %s\n", lkl_strerror(ret));
return;
Expand Down
5 changes: 3 additions & 2 deletions tools/lkl/lklfuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,10 @@ const struct fuse_operations lklfuse_ops = {
static int start_lkl(void)
{
long ret;
char mpoint[32];
char mpoint[32], cmdline[16];

ret = lkl_start_kernel(&lkl_host_ops, lklfuse.mb * 1024 * 1024, "");
snprintf(cmdline, sizeof(cmdline), "mem=%dM", lklfuse.mb);
ret = lkl_start_kernel(&lkl_host_ops, cmdline);
if (ret) {
fprintf(stderr, "can't start kernel: %s\n", lkl_strerror(ret));
goto out;
Expand Down
2 changes: 1 addition & 1 deletion tools/lkl/tests/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ int main(int argc, char **argv)
if (cla.tap_ifname)
TEST(netdev_add);
#endif /* __MINGW32__ */
lkl_start_kernel(&lkl_host_ops, 16 * 1024 * 1024, "loglevel=8");
lkl_start_kernel(&lkl_host_ops, "mem=16M loglevel=8");

TEST(getpid);
TEST(syscall_latency);
Expand Down
6 changes: 6 additions & 0 deletions tools/lkl/tests/hijack-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ echo "$ans" | grep "0x0" # lo's dev_id
# it here.
! echo "$ans" | grep "WARN: failed to free"

# boot_cmdline test
echo "== boot command line tests =="
ans=$(LKL_HIJACK_DEBUG=1\
LKL_HIJACK_BOOT_CMDLINE="mem=100M" ${hijack_script} ip ad)
echo "$ans" | grep "100752k"

echo "== TAP tests =="
if [ ! -c /dev/net/tun ]; then
echo "WARNING: missing /dev/net/tun, skipping TAP and VDE tests."
Expand Down
2 changes: 1 addition & 1 deletion tools/lkl/tests/net-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static int test_net_init(int argc, char **argv)
if ((ip && !strcmp(ip, "dhcp")) && (nd_id != -1))
snprintf(boot_cmdline, sizeof(boot_cmdline), "ip=dhcp");

ret = lkl_start_kernel(&lkl_host_ops, 64 * 1024 * 1024, boot_cmdline);
ret = lkl_start_kernel(&lkl_host_ops, boot_cmdline);
if (ret) {
fprintf(stderr, "can't start kernel: %s\n", lkl_strerror(ret));
return -1;
Expand Down

0 comments on commit bc3fe96

Please sign in to comment.