Skip to content

auto generating task#441

Closed
Suryansh-Dey wants to merge 4 commits intoluainkernel:masterfrom
Suryansh-Dey:task-phased-v2
Closed

auto generating task#441
Suryansh-Dey wants to merge 4 commits intoluainkernel:masterfrom
Suryansh-Dey:task-phased-v2

Conversation

@Suryansh-Dey
Copy link
Copy Markdown
Contributor

@Suryansh-Dey Suryansh-Dey commented Feb 21, 2026

Closes #435
Here is phase 1 of the PR

  • Simplify configure.lua (remove stat, signal, eth, supplement logic)
  • Restore lualinux_stat in lib/lualinux.c
  • Update documentation for task access

Now make configure auto generates hexadecimal constants for both task and stat modules.

Phase 2: Move stat constants
Phase 3: Move OR'ed flags (composites)
Ready for the feedback.

@Suryansh-Dey Suryansh-Dey mentioned this pull request Feb 21, 2026
Comment thread lib/lualinux.c Outdated
Comment thread configure.lua Outdated
Comment thread lib/lualinux.c
@Suryansh-Dey
Copy link
Copy Markdown
Contributor Author

I did run the relevant tests and nothing seem to break:

~/dev/GSOC/lunatik task-phased-v2 [!]
❯ sudo lunatik reload
  sudo lunatik status
[sudo] password for suryansh:
lunatik is loaded
luadevice is loaded
lualinux is loaded
luanotifier is loaded
luasocket is loaded
luarcu is loaded
luathread is loaded
luafib is loaded
luadata is loaded
luaprobe is loaded
luasyscall is loaded
luaxdp is loaded
luafifo is loaded
luaxtable is loaded
luanetfilter is loaded
luacompletion is loaded
luacrypto_shash is loaded
luacrypto_skcipher is loaded
luacrypto_aead is loaded
luacrypto_rng is loaded
luacrypto_comp is loaded
luacpu is loaded
luahid is loaded
luasignal is loaded
luabyteorder is loaded
lunatik_run is loaded
~/dev/GSOC/lunatik task-phased-v2 [!]
❯ echo 'local task = require("linux.task"); print(task.INTERRUPTIBLE, task.UNINTERRUPTIBLE, task.KILLABLE, task.IDLE); return "task OK"' | sudo lunatik
  sudo dmesg | tail -5
Lunatik 4.1  Copyright (C) 2023-2026 Ring Zero Desenvolvimento de Software LTDA.
> task OK
> [  610.149922] 2
[  610.149924]
[  610.149925] 258
[  610.149927]
[  610.149928] 1026
~/dev/GSOC/lunatik task-phased-v2 [!]
❯ echo 'local linux = require("linux"); local task = require("linux.task"); linux.schedule(100, task.INTERRUPTIBLE); return "schedule OK"' | sudo lunatik

Lunatik 4.1  Copyright (C) 2023-2026 Ring Zero Desenvolvimento de Software LTDA.
> schedule OK
>
~/dev/GSOC/lunatik task-phased-v2 [!]
❯ echo 'local linux = require("linux"); print(linux.stat.IRUGO); return "stat OK"' | sudo lunatik
  sudo dmesg | tail -1
Lunatik 4.1  Copyright (C) 2023-2026 Ring Zero Desenvolvimento de Software LTDA.
> stat OK
> [  710.751080] 292

Got 292 as expected.

What should I do with examples/shared.lua and example/echod/daemon.lua? Remove the line to get rid of linter error?

Comment thread configure.lua Outdated
@Suryansh-Dey Suryansh-Dey force-pushed the task-phased-v2 branch 2 times, most recently from 34d4bb1 to fcb04eb Compare February 22, 2026 12:38
@lneto
Copy link
Copy Markdown
Contributor

lneto commented Feb 22, 2026

I did run the relevant tests and nothing seem to break:

you did break the examples, right? we shouldn't break anything.

What should I do with examples/shared.lua and example/echod/daemon.lua? Remove the line to get rid of linter error?

you should adjust the examples accordingly.

Copy link
Copy Markdown
Contributor Author

@Suryansh-Dey Suryansh-Dey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved

if tonumber(value) then return value end

to

	local n = tonumber(value)
	if n then return string.format("0x%08x", n) end

To avoid mixing octal and hex. Or should I keep it octal?
(Git diff seem to glitch a bit there so better you look at the new code instead of looking at the diff)

Comment thread configure.lua Outdated
Comment thread lib/lualinux.c
@Suryansh-Dey Suryansh-Dey force-pushed the task-phased-v2 branch 2 times, most recently from 5d75ba8 to 64c7234 Compare February 22, 2026 14:29
@lneto
Copy link
Copy Markdown
Contributor

lneto commented Feb 26, 2026

@Suryansh-Dey are you still working on this? please, let me know.

@Suryansh-Dey
Copy link
Copy Markdown
Contributor Author

I have exams tomorrow and day after tomorrow, I will get back to it on 28th feb.

@lneto
Copy link
Copy Markdown
Contributor

lneto commented Feb 26, 2026

I have exams tomorrow and day after tomorrow, I will get back to it on 28th feb.

good luck! no worries, just wanted to check if we should keep this PR opened.. thanks!

@Suryansh-Dey Suryansh-Dey force-pushed the task-phased-v2 branch 3 times, most recently from 804d1c7 to 55e8947 Compare March 1, 2026 17:48
Comment thread configure.lua
local function resolve_value(value, constants, prefix, module_name, seen)
if tonumber(value) then return value end
local function resolve_value(value, constants, seen)
if tonumber(value) then return tonumber(value) end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because write_constants now uses string.format('0x%08x', resolved_value) which requires an actual number, not a string. The original returned the raw string "0x00000001" and wrote it with %s.
We need it for:

  • Format it consistently as 0x%08x
  • Use the bitwise OR operator result | resolved for composite constants like TASK_KILLABLE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems odd to me to convert it twice.. perhaps you should use tonumber on the caller and if type is number here, return it.. not sure.. but you should clean up your logics.. it seems very convoluted to me..

Comment thread configure.lua Outdated
Comment thread configure.lua Outdated
@lneto
Copy link
Copy Markdown
Contributor

lneto commented Mar 1, 2026

@sneaky-potato can you please review it? It's your baby ;-)

Comment thread configure.lua Outdated
is_or_expr = false
break
end
local resolved = resolve_value(constants[token] or token, prefix, constants, seen)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, if seen is nil at the top level (first call), each component initializes its own independent seen in the calls of resolve_value. For it to work correctly, seen must be defined at the top of this function I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have added some safety checks without compromising performance.

Comment thread configure.lua Outdated
@Suryansh-Dey Suryansh-Dey force-pushed the task-phased-v2 branch 3 times, most recently from 6cec57b to 5f7de2f Compare March 6, 2026 08:18
Comment thread configure.lua
if tonumber(value) then return tonumber(value) end
seen = seen or {}
-- recursion check: avoid cyclic defines
if seen[value] then return nil end
Copy link
Copy Markdown
Member

@sneaky-potato sneaky-potato Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't move this. Keep this block above the main loop only, it will allow the method to return early if the macro has been seen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread Makefile Outdated
remove [%w_]+ regex from resolve_value

Updating makefile to provide arch

Update Makefile

Co-authored-by: Ashwani Kumar Kamal <75236490+sneaky-potato@users.noreply.github.com>
@Suryansh-Dey Suryansh-Dey force-pushed the task-phased-v2 branch 2 times, most recently from 4a1a811 to 57c4715 Compare March 8, 2026 10:17
Comment thread lib/lualinux.c
Comment thread configure.lua Outdated
Comment thread configure.lua Outdated
Comment thread configure.lua
local function resolve_value(value, constants, prefix, module_name, seen)
if tonumber(value) then return value end
local function resolve_value(value, constants, seen)
if tonumber(value) then return tonumber(value) end
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because write_constants now uses string.format('0x%08x', resolved_value) which requires an actual number, not a string. The original returned the raw string "0x00000001" and wrote it with %s.
We need it for:

  • Format it consistently as 0x%08x
  • Use the bitwise OR operator result | resolved for composite constants like TASK_KILLABLE

Comment thread configure.lua Outdated
Comment thread configure.lua Outdated
Comment thread configure.lua Outdated
is_or_expr = false
break
end
local resolved = resolve_value(constants[token] or token, prefix, constants, seen)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have added some safety checks without compromising performance.

Comment thread configure.lua
if tonumber(value) then return tonumber(value) end
seen = seen or {}
-- recursion check: avoid cyclic defines
if seen[value] then return nil end
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread Makefile Outdated
Comment thread configure.lua
module_name = "eth",
},
{
header = "uapi/linux/stat.h",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to linux/stat.h ensures the CPP sees both the UAPI base constants and the internal compound ones like S_IRUGO = (S_IRUSR|S_IRGRP|S_IROTH), which our resolve_value function then resolves into their final numeric values.

@Suryansh-Dey
Copy link
Copy Markdown
Contributor Author

Suryansh-Dey commented Mar 9, 2026

All the tests are passing now. If the PR is ready to merge and no changes needed I can squash the commits. Please let me know

Comment thread configure.lua Outdated
Comment thread configure.lua Outdated
Comment on lines +46 to +47
local BUILD = INCLUDE:gsub("/include$", "")
local CPP = string.format("%s -E -dM -I%s -I%s/include/generated -I%s/arch/%s/include -I%s/arch/%s/include/generated -include linux/kconfig.h",
Copy link
Copy Markdown
Member

@sneaky-potato sneaky-potato Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we should accept BUILD as a command line argument instead of INCLUDE to the script.
INCLUDE would then become BUILD .. "/include"
This way we can construct the other paths as well instead of relying on string manipulation.

If you notice in Makefile we already have a variable ${MODULES_BUILD_PATH}
What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you wish

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you wish

don't you agree with the suggestions? if so, please make your point..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I do agree. I also think it is cleaner.

Comment thread configure.lua
if clean:find("|") then
local result = 0
for token in clean:gmatch("[^%s|]+") do
local resolved = resolve_value(token, prefix, constants, seen)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are not setting seen[value] = true right before this resolve_value call. This might cause problems right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this won't cause any problems.
The value at this specific point is the literal OR expression string itself. We only need to track the actual macro names in the seen table to detect cycles. Since each individual token inside the OR expression (like TASK_A and TASK_B) gets passed back into resolve_value recursively, they will hit the seen[value] = true block at the bottom when they are resolved as macro references. If an OR expression contains a macro that forms a cycle, it will still be caught perfectly.
Please correct me If I missed something

Comment thread Makefile Outdated
@@ -12,6 +12,8 @@ MODULES_BUILD_PATH ?= ${BTF_INSTALL_PATH}
MODULES_INSTALL_PATH := ${MODULES_RELEASE_PATH}/kernel
SCRIPTS_INSTALL_PATH := ${MODULES_PATH}/lua
INCLUDE_PATH := ${MODULES_BUILD_PATH}/include
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used anywhere now, we can safely remove this

Copy link
Copy Markdown
Contributor Author

@Suryansh-Dey Suryansh-Dey Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MODULES_INSTALL_PATH := ${MODULES_RELEASE_PATH}/kernel
SCRIPTS_INSTALL_PATH := ${MODULES_PATH}/lua

They get used later in the makefile below, so we can't remove them.
But yes I should have removed line 14. My bad.

Comment thread Makefile Outdated
SCRIPTS_INSTALL_PATH := ${MODULES_PATH}/lua
INCLUDE_PATH := ${MODULES_BUILD_PATH}/include
KERNEL_ARCH ?= ${shell uname -m}
ARCH ?= $(subst x86_64,x86,$(subst aarch64,arm64,$(KERNEL_ARCH)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am having mixed feelings here. We already do similar logic to find architecture here in KBuild. Maybe export this as environment variable so that both the Kbuild and configure.lua simply "consume" instead of recomputing it.
@lneto what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never reinvent the wheel.. BTW, we should care about cross compiling; particularly, this should work with OpenWRT feed as well..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I do then?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @sneaky-potato's idea is way to do it, just make sure it works on OpenWRT feed. It must be tested there as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please test if works on OpenWRT feed. I am not sure of that thing, how it works.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can help if you would like to do it, but not do it for you. For merging this PR, we need to make sure we don't break it. For building it you can just use our OpenWRT feed pointing to your commit. You probably will need to adjust the makefile there.

Co-authored-by: Ashwani Kumar Kamal <75236490+sneaky-potato@users.noreply.github.com>
@lneto lneto closed this Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

move lualinux_task and lualinux_stat to configure.lua

3 participants