#EvalynOS

1 messages · Page 34 of 1

wide mica
#

"the other parts of the memcpy slow it down" wdym

hazy saddle
#

Sorry my wording is ass I haven't slept all day

#

Trying to reset sleep schedule to not be total BS

#

The parts of the loop where it checks alignment and other things was causing the 16b part to be slower in alot of cases when not using single byte copies

#

Though some other changes I made lessened that do maybe I can just swap if back to 8b?

#

Probably needs more micro benchmarking I don't want to fucking do

#

And when I compile with -o3 / lto eveything just shits the floor and ends up fast as fuck anyways (but not in an invalid way)

#

So some of my test methods may not be fully good since it's adhoc shoved into the kernel

#

I do wonder why when it should be looping and be mostly 1:1 the gap increases instead of not on there

#

But on x86 it's fine it seems

#

Both ran on bare metal so no scheduling bs with VMs/tcg

dark lotus
#

Omg you're still on memset 😭

#

@hazy saddle For memcpy, wouldn't it be faster to use ERMS? If you're not targetting a CPU older then 2012

Atleast, that's what i do for my memcpy, I'm not sure if it's faster or slower

        __asm__ volatile("rep movsb" : "+D"(Dest), "+S"(Src), "+c"(Count) : : "memory");

hazy saddle
#

Just for copies larger than 2k

dark lotus
hazy saddle
#

Depends on alignments

#

Look at the benchmarks for things above 2k

#

And look how much it can vary

#

On my 5700x

dark lotus
hazy saddle
#

Above 2kb most of my workloads are going to be page copies of half pages of so

#

So it's on average best to use it there iirc

#

ERMS also has startup overhead too

young hamlet
hazy saddle
young hamlet
hazy saddle
#

What's the instruction for doing then on GPRs?

#

Also I don't really wanna make it super importable and have a bunch of ifdefs

#

And I wonder if that's even appropriate for a memcpy

young hamlet
young hamlet
young hamlet
coarse oasis
#

are non-temporal stores safe to do if the target is in cache?

young hamlet
#

It’ll still adhere to the CC policy

hazy saddle
#

I'd probably want an mfence too before returning right? And I presume only normal loads too

young hamlet
coarse oasis
#

the sdm says

The non-temporal hint is implemented by using a write combining (WC) memory type protocol when writing the data to memory. Using this protocol, the processor does not write the data into the cache hierarchy, nor does it fetch the corresponding cache line from memory into the cache hierarchy.

#

loads from wc mem might be incoherent with stores still in the wc buffer

#

iirc

young hamlet
#

I see, if there aren’t loads coming soon after this it should be fine though nah?

hazy saddle
young hamlet
#

Like you can use a fence directly after

coarse oasis
#

i mean, if i understand right, this would be broken? ```
; assume [rdi] != 0
mov eax, [rdi]
xor eax, eax
movnti [rdi], eax
mov eax, [rdi]
; eax might be != 0 because the cache line remains

young hamlet
hazy saddle
#

That could be an issue with the bulk copies?

young hamlet
coarse oasis
hazy saddle
#

I can't test it yaaar

coarse oasis
#

or i'm confusing something

#

i tried testing it locally with ```x86asm
global main
main:
mov eax, 0x41414141
lea rdi, [rel foo]
mov [rdi], eax
xor eax, eax
movnti [rdi], eax
mov eax, [rdi]
ret

section .data

foo: dd 0x42424242

#

i think i might be confusing this with wc cacheability on pages from pat

#

since there reads are treated as uc and bypass any on-cpu buffers

young hamlet
#

I think that if large data copying is excessive, it may be worth it to try non temporal stores at least (loads you might still not want to use non temporal operations for to allow for the cache to prefetch data you’re copying)

#

If it improves performance stick with it if not just stick with what you’re using now

#

But it is probably worthwhile to look into

hazy saddle
#

I think il stick with my current function

#

And come back and try and fix it up more

#

But it's probably fineee

#

And in most cases other than super tiny ops it's alot better

hazy saddle
#

Il try and maybe make a more reliable bench?

coarse oasis
young hamlet
coarse oasis
#

PREFETCHNTA could help maybe?

young hamlet
#

True that

hazy saddle
#

😭

#

and neither i or clanker can figure out why tf its doing that

tender mantle
hazy saddle
#

I mean it's probably fine since release builds will want to be done with LTO anyways :p

#

And it's something I fully support

hazy saddle
#

i wonder if on @tawny wren's clankered riscv core thats more fancy would fare better PSP1G_pspTrollar

#

since this also doesnt show in x86

#

and this ends up being something that the smaller CPU struggles with predicting branches etc and crap

hazy saddle
#

Okay now for me to try and get the energy to review this shit

#

And commit and push

#

And then fuck

#

What was on my list of things to do next?

wraith star
#

porting bash

hazy saddle
#

I think there was one other thing than timers?

#

Right it was the RBtree rework

#

To save 8 bytes

#

I'm also thinking about stuff like LAM

#

Yes it's a cool feature

#

but

#

It sucks ass how I can't really use it

#

On 5 level paging it wouldn't give me enough bits for what id want to use it for

#

Eg I don't think it can even fit a u8?

#

And it's really architecture dependant

#

And even CPU dependant with paging modes

#

What sucks is I can't run different parts of the address space with different paging modes

#

Because the kernel could get forced to a 4 level mode

wraith star
#

if you are really into saving bits, you can force pointers to be aligned and have your data in the lower bits of the pointers

hazy saddle
#

But even then support is not there yet for it to be viable

hazy saddle
#

Since they are all 8 byte aligned

#

And rbtrees only need one bit

wraith star
#

and if you are always working with kernel data structures

#

you can ignore the fact that you dont have lam

#

you can always or the uppers bits with 0xff...

#

although this will get very shitty if you have multiple arches

hazy saddle
#

The point of lam is a speed one not an embedding

tender mantle
#

first thing I get when I search for intel lam lol

hazy saddle
#

Just sucks it's a little not feesible to use even in userspace

tender mantle
#

> the Linux kernel is now disabling LAM out of security concerns.

wraith star
#

Based

hazy saddle
tender mantle
#

lmfao

hazy saddle
#

LAM is just stupid on x86

#

As long as the page walkers aren't flexible

#

Since a program can't say it wants 4/5 level paging

#

Atleast then the software could be somewhat portableish

tender mantle
#

> When LASS is enabled, the processor hardware monitors memory access based on the current CPU privilege level (CPL):
> User Space Access: If user-mode software attempts to access an address in the upper half (kernel space), a General Protection Fault (#GP) is generated.

#

INTEL

#

WHY

wraith star
#

i suppose for guarding against meltdown

tender mantle
#

welp add another random fucking reason for general protection faults to happen

tender mantle
#

the problem is raising a gp

wraith star
#

eh

#

just kill the user task

#

as with any other #gp

tender mantle
#

gps can be caused by like 40 different things atp

wraith star
#

the only problem is that you wont be able to send a page fault to the process

#

but whatever

tender mantle
#

oh it also prevents the kernel from accessing user memory

hazy saddle
#

This wouldn't be an issue if FRED added GPF source reporting

#

And they do have fields to allow this btw

tender mantle
#

I mean it does

#

it's just error code 0 means "any generic error"

hazy saddle
#

That's the issue

tender mantle
wraith star
#

if fred were to report the reason for #gp you would run out of bits

#

lol

tender mantle
#

it's a uint64_t lol

wraith star
#

breathing already is a cause for #gp

#

ah okay

hazy saddle
tender mantle
hazy saddle
hazy saddle
#

Sorry

tender mantle
#

259

  • 1 per idt entry
  • 1 for gdt errors
  • 1 for ldt errors
  • 1 for "generic error"
hazy saddle
#

Too far 😭

#

Damn

tender mantle
#

if you wanna count 1 per segment selector as well trl

hazy saddle
#

I meant I went too far

tender mantle
clear bison
#

GPF due to SMP startup trl

tender mantle
#

the worst one imo

#

> Executing an SSE/SSE2/SSE3 instruction that attempts to access a 128-bit memory location that is not aligned on a 16-byte boundary when the instruction requires 16-byte alignment. This condition also applies to the stack segment.

#

because there is LITERALLY AN EXCEPTION CALLED "ALIGNMENT CHECK"

tawny wren
#

How fast are the cores in the vf2 again?

hazy saddle
#

And I mostly mean some weird asf behavior with the memset at O2

tawny wren
hazy saddle
#

Where small copies progressively take wayyyy longer than a naive loop despite being the same code

tawny wren
#

I don't think I'll be able to get my FPGA to beat that raw performance lol

hazy saddle
#

Unless you use lto

#

It's mostly relative mcycle count between two algorithms I need to see

tawny wren
hazy saddle
#

Not easy performance

hazy saddle
tawny wren
#

It should

hazy saddle
#

That's why I tried micro benchmarking so much

tawny wren
#

It's some sifive core

tender mantle
hazy saddle
#

I even put a clanker on it

#

And that wouldn't work with LTO memes and other crap

#

Look at the benchmarks I posted up thetr

hazy saddle
#

😭

tender mantle
#

I'm more curious in the actual assembly difference if it's the same code

hazy saddle
#

i meant the inner loop

#

that should be executing

#

between the two functions being benched

#

for small things

tender mantle
#

yeah I have no clue, I'm eepy and this isn't making any sense

hazy saddle
#

feel free to look

hazy saddle
#

lmao

#

i think it optimized it into the korona memcpy

#

Or I mean

#

A similar algorithm 😭

#

Just for memset instead

tawny wren
#

given what i very quickly googled about the sifive core

hazy saddle
#

ah lol

tawny wren
#

since its in-order multi-issue the compiler will be trying to schedule the instructions in such a way that the cpu retires as many as possible

#

since the cpu wont reorder them on its own

hazy saddle
#

Which is also what the korona memcpy does I think? It's basically a bunch of chunks of progressively smaller copies until it does one byte and can return

tawny wren
#

itll also probably implicitly know a bit more about the core and memory and shit as well, but i wouldnt be surprised if there are other ways to make the generic one do that too since it would make sense in general i think

hazy saddle
#

well time to run a benchmark

#

lol that fixed it

#

it still has some losses with strange non word sized alignments above 8b

#

but thats fine

#

since its some weird af shit to have a struct thats not word size aligned AND larger than a word size

#

so it ended up just being a poopy cpu that needed an mtune flag

cyan bison
#

😔

hazy saddle
#

It makes my code was fine

cyan bison
#

oh yay

#

🎉

hazy saddle
#

It's also why this didn't happen on a 5700x

cyan bison
#

ill be back to chip in in a few months

hazy saddle
#

Because zen3 is a good uarch

tender mantle
tender mantle
hazy saddle
tender mantle
#

The cpu equivalent of hydrogen bomb vs coughing baby

cyan bison
#

-# would it work on an 8086 trl

hazy saddle
#

i mean

#

this still has some tricks

#

its still multi issue

#

and its not fully weak

#

a coughing baby would be a super simple core that takes many cycles to execute one opcode and has no fancy tricks

tender mantle
#

2 pipelines no ooo riscv64 cpu vs god knows how many pipelines, ooo & speculative x86_64 cpu

hazy saddle
#

this is more like a toddler of CPUs

tender mantle
#

Oh slightly better

#

What’s x86_64 then?

hazy saddle
hazy saddle
hazy saddle
#

i was looking back at my riscv/la64 interrupt code

#

some of the comments were a little unclear imo?

#

i changed it from

    bnez t1, 1f             # branch if from kernel mode
    ld t1, 0(t0)            # load current thread pointer if from user mode
    ld sp, 0(t1)            # get kernel stack pointer
    1:                      # else proceed

to

    bnez t1, 1f             # if from usermode {
    ld t1, 0(t0)                # load current thread pointer
    ld sp, 0(t1)                # get kernel stack pointer
    1:                      # }
#

commit message for tomorrow

Optimize memcpy and memset

Also make risc-v and loongarch64 interrupt comments more clear
#

actually

#

i dont know if i should change them?

pallid vine
hazy saddle
#

And I try and keep the main message under 50 characters etc

pallid vine
#

yea that makes sense

hazy saddle
#

another thing ive been considering is stripping nasm as a dependancy

#

and redoing things into GAS + intel synax setting