Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs452Trainee
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tom Feng
cs452Trainee
Commits
a27db952
Commit
a27db952
authored
6 years ago
by
Tom Feng
Browse files
Options
Downloads
Plain Diff
Merge branch 'kernel2' into 'k2merge'
# Conflicts: # lib/buffer.c # lib/rps.c
parents
85b43580
2598b051
No related branches found
No related tags found
1 merge request
!2
due date morning, rps doesn't work
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/buffer.c
+1
-1
1 addition, 1 deletion
lib/buffer.c
lib/rps.c
+23
-27
23 additions, 27 deletions
lib/rps.c
src/k2PerfTest.c
+71
-15
71 additions, 15 deletions
src/k2PerfTest.c
with
95 additions
and
43 deletions
lib/buffer.c
+
1
−
1
View file @
a27db952
...
...
@@ -77,4 +77,4 @@ int BufferShrinkFIFO(Buffer* Buf, int Num)
Buf
->
Head
=
(
Buf
->
Head
+
ActualShrink
)
%
Buf
->
Size
;
return
0
;
}
else
return
BUFF_NOTREADY
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/rps.c
+
23
−
27
View file @
a27db952
...
...
@@ -164,25 +164,23 @@ int Player(int ID){
SendMsg
.
Choice
=
Paper
;
break
;
}
else
if
(
Input
==
's'
||
Input
==
'S'
)
{
SendMsg
.
Choice
=
Scissors
;
break
;
}
else
if
(
Input
==
'q'
||
Input
==
'Q'
){
SendMsg
.
Msg
=
Quit
;
}
else
{
Input
=
'U'
;
bwprintf
(
COM2
,
"Please enter r/R for Rock, p/P for Paper, s/S for Scissors.
\n\r
"
);
}
}
SendMsg
.
Msg
=
Play
;
Result
=
Send
(
ServerTID
,
&
SendMsg
,
sizeof
(
SendMsg
),
&
ReplyMsg
,
sizeof
(
ReplyMsg
));
if
(
Result
!=
sizeof
(
ReplyMsg
))
{
if
(
SendMsg
.
Msg
==
Quit
){
bwprintf
(
COM2
,
"Request for QUIT from %s did not go through gracefully."
,
Name
);
}
else
{
bwprintf
(
COM2
,
"%s: Game obstructed!"
,
Name
);
char
Input
=
'U'
;
// for Undefined
RPSMsgType
RPSResult
;
int
MyTID
,
ServerID
,
Result
;
RPSMessage
SendMsg
,
ReplyMsg
;
MyTID
=
MyTid
();
bwprintf
(
COM2
,
"%s with TaskID(%d) is about to Play
\n\r
"
,
Name
,
MyTID
);
ServerTID
=
WhoIs
(
"RPSServer"
);
if
(
ServerTID
<
0
)
return
FAILURE
;
SendMsg
.
Msg
=
SignUp
;
Result
=
Send
(
ServerTID
,
&
SendMsg
,
sizeof
(
SendMsg
),
&
ReplyMsg
,
sizeof
(
ReplyMsg
));
if
(
Result
!=
sizeof
(
ReplyMsg
))
{
bwprintf
(
COM2
,
"Sign Up Request to Server did not go through."
);
return
Result
;
}
return
FAILURE
;
}
else
{
...
...
@@ -190,19 +188,17 @@ int Player(int ID){
bwprintf
(
COM2
,
"%s exitting..."
,
Name
);
Result
=
ReplyMsg
.
Msg
;
}
}
}
return
SUCCESS
;
return
SUCCESS
;
}
int
RPSClient1
(){
Player
(
1
);
Exit
();
Player
(
1
);
Exit
();
}
int
RPSClient2
(){
Player
(
2
);
Exit
();
}
Player
(
2
);
Exit
();
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/k2PerfTest.c
+
71
−
15
View file @
a27db952
#include
<k2PerfTest.h>
#include
<timer.h>
#include
<syscall.h>
#include
"nameserver.h"
void
HelloWorld
()
{
bwprintf
(
COM2
,
"Hello World
\n\r
"
);
void
Sender
()
{
int
ReceiverTID
,
Result
,
i
,
startTime
,
endTime
;
int
sum
=
0
;;
int
SendMsg
,
ReplyMsg
;
Clock
*
c
;
ClockInit
(
c
);
ReceiverTID
=
WhoIs
(
"Rcvr"
);
for
(
i
=
0
;
i
<
100
;
++
i
)
{
ClockUpdate
(
c
);
startTime
=
c
->
ClockCount
;
Send
(
ReceiverTID
,
(
void
*
)
SendMsg
,
sizeof
(
SendMsg
),
(
void
*
)
ReplyMsg
,
sizeof
(
ReplyMsg
));
ClockUpdate
(
c
);
endTime
=
c
->
ClockCount
;
sum
+=
endTime
-
startTime
;
}
sum
/=
100
;
bwprintf
(
COM2
,
"Time:
\n\r
"
,
sum
);
Exit
();
}
void
Receiver
()
{
int
SenderTID
,
Result
,
i
,
StartTime
,
EndTime
;
int
sum
=
0
;
int
ReceiveMsg
,
ReplyMsg
;
// 4 bytes
Clock
*
c
;
ClockInit
(
c
);
Result
=
RegisterAS
(
"Rcvr"
);
Receive
(
&
SenderTID
,
(
void
*
)
ReceiveMsg
,
sizeof
(
ReceiveMsg
));
Reply
(
SenderTID
,
ReplyMsg
,
sizeof
(
ReplyMsg
));
x
for
(
i
=
0
;
i
<
100
;
i
++
)
{
ClockUpdate
(
c
);
startTime
=
c
->
ClockCount
;
Receive
(
&
senderTid
,
ReceiveMsg
,
sizeof
(
ReceiveMsg
));
ClockUpdate
(
c
);
endTime
=
c
->
ClockCount
;
Reply
(
SenderTID
,
ReplyMsg
,
sizeof
(
ReplyMsg
));
sum
+=
(
EndTime
-
StartTime
);
}
sum
/=
100
;
bwpritnf
(
COM2
,
"Time: %d
\n\r
"
,
sum
);
Exit
();
}
void
PerfTest
()
{
int
Task1ID
,
Task2ID
;
int
i
;
char
SendMsg
[
6
]
=
"CS452"
;
int
SendMsgLen
=
6
,
ReplyMsgLen
=
6
;
char
Reply
[
6
];
int
SenderTID
,
ReceiverTID
,
NSTID
,
SendFirst
=
1
;
AP
Args1
,
Args5
,
Args
;
char
*
SendMsg
,
ReplyMsg
;
AP
*
Args4
;
Args4
->
arg0
=
(
PrioLvl
)
Prio4
;
Args4
->
arg1
=
(
void
*
)
(
&
HelloWorld
);
Args5
.
arg0
=
(
void
*
)
Prior5
;
Args5
.
arg1
=
(
void
*
)
(
&
Receiver
);
Task1ID
=
Create
(
&
Args4
);
Args1
.
arg0
=
(
void
*
)
Prior1
;
Args1
.
arg1
=
(
void
*
)
(
&
Receiver
);
Task2ID
=
Create
(
&
Args4
);
Args
.
arg1
=
(
void
*
)
(
&
Receiver
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
Send
(
Task1ID
,
SendMsg
,
SendMsgLen
,
ReplyMsgLen
,
}
NSTID
=
Create
(
&
Args1
);
if
(
SendFirst
)
Args
.
arg0
=
(
void
*
)
Prior3
;
else
Args
.
arg0
=
(
void
*
)
Prio7
;
ReceiverTID
=
Create
(
&
Args
);
Args5
.
arg1
=
(
void
*
)(
&
Sender
);
SenderTID
=
Create
(
&
Args5
);
Send
(
ReceiverTID
,
(
void
*
)
SendMsg
,
sizeof
(
SendMsg
),
(
void
*
)
Reply
,
sizeof
(
ReplyMsg
));
Exit
();
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment