Skip to content

Commit 3c95771

Browse files
authored
Merge pull request #510 from intel-go/ifilippo/kni
Release KNI while stopping system
2 parents 8eb845e + 0726d33 commit 3c95771

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

common/common.go

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const (
154154
WrongPort
155155
FailToInitDPDK
156156
FailToCreateKNI
157+
FailToReleaseKNI
157158
)
158159

159160
// NFError is error type returned by nff-go functions

flow/flow.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ type port struct {
375375
txQueuesNumber int16
376376
willReceive bool // will this port receive packets
377377
willKNI bool // will this port has assigned KNI device
378+
KNICoreIndex int
378379
port uint16
379380
MAC [common.EtherAddrLen]uint8
380381
InIndex int32
@@ -601,7 +602,7 @@ func SystemStart() error {
601602

602603
// SystemStop stops the system. All Flow functions plus resource releasing
603604
// Doesn't cleanup DPDK
604-
func SystemStop() {
605+
func SystemStop() error {
605606
// TODO we should release rings here
606607
schedState.systemStop()
607608
for i := range createdPorts {
@@ -611,8 +612,17 @@ func SystemStop() {
611612
createdPorts[i].txQueuesNumber = 0
612613
createdPorts[i].willReceive = false
613614
}
615+
if createdPorts[i].willKNI {
616+
err := low.FreeKNI(createdPorts[i].port)
617+
if err != nil {
618+
return err
619+
}
620+
schedState.setCoreByIndex(createdPorts[i].KNICoreIndex)
621+
createdPorts[i].willKNI = false
622+
}
614623
}
615624
low.FreeMempools()
625+
return nil
616626
}
617627

618628
// SystemReset stops whole framework plus cleanup DPDK
@@ -1566,19 +1576,20 @@ func CreateKniDevice(portId uint16, name string) (*Kni, error) {
15661576
if createdPorts[portId].willKNI {
15671577
return nil, common.WrapWithNFError(nil, "Requested KNI port already has KNI. Two KNIs for one port are prohibited.", common.MultipleKNIPort)
15681578
}
1569-
if core, _, err := schedState.getCore(); err != nil {
1579+
if core, coreIndex, err := schedState.getCore(); err != nil {
15701580
return nil, err
15711581
} else {
15721582
if err := low.CreateKni(portId, uint(core), name); err != nil {
15731583
return nil, err
15741584
}
1585+
kni := new(Kni)
1586+
// Port will be identifier of this KNI
1587+
// KNI structure itself is stored inside low.c
1588+
kni.portId = portId
1589+
createdPorts[portId].willKNI = true
1590+
createdPorts[portId].KNICoreIndex = coreIndex
1591+
return kni, nil
15751592
}
1576-
kni := new(Kni)
1577-
// Port will be identifier of this KNI
1578-
// KNI structure itself is stored inside low.c
1579-
kni.portId = portId
1580-
createdPorts[portId].willKNI = true
1581-
return kni, nil
15821593
}
15831594

15841595
func FillSliceFromMask(input []uintptr, mask *[burstSize]bool, output []uintptr) uint8 {

flow/scheduler.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ type scheduler struct {
171171
pAttempts []uint64
172172
maxInIndex int32
173173
measureRings low.Rings
174+
coreIndex int
174175
}
175176

176177
type core struct {
@@ -204,7 +205,7 @@ func newScheduler(cpus []int, schedulerOff bool, schedulerOffRemove bool, stopDe
204205
func (scheduler *scheduler) systemStart() (err error) {
205206
scheduler.stopFlag = process
206207
var core int
207-
if core, _, err = scheduler.getCore(); err != nil {
208+
if core, scheduler.coreIndex, err = scheduler.getCore(); err != nil {
208209
return err
209210
}
210211
common.LogDebug(common.Initialization, "Start SCHEDULER at", core, "core")
@@ -333,9 +334,9 @@ func (scheduler *scheduler) systemStop() {
333334
scheduler.ff[i].stopInstance(0, -1, scheduler)
334335
}
335336
}
336-
scheduler.setCoreByIndex(0) // scheduler
337+
scheduler.setCoreByIndex(scheduler.coreIndex)
337338
if scheduler.stopDedicatedCore {
338-
scheduler.setCoreByIndex(1) // stop
339+
scheduler.setCoreByIndex(scheduler.coreIndex + 1)
339340
}
340341
scheduler.ff = nil
341342
}

low/low.go

+7
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,13 @@ func StopPort(port uint16) {
515515
C.rte_eth_dev_stop(C.uint16_t(port))
516516
}
517517

518+
func FreeKNI(port uint16) error {
519+
if C.free_kni(C.uint16_t(port)) < 0 {
520+
return common.WrapWithNFError(nil, "Problem with KNI releasing\n", common.FailToReleaseKNI)
521+
}
522+
return nil
523+
}
524+
518525
// GetPortsNumber gets total number of available Ethernet devices.
519526
func GetPortsNumber() int {
520527
return int(C.rte_eth_dev_count())

low/low.h

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ int create_kni(uint16_t port, uint32_t core, char *name, struct rte_mempool *mbu
150150
return 0;
151151
}
152152

153+
int free_kni(uint16_t port) {
154+
return rte_kni_release(kni[port]);
155+
}
156+
153157
int checkRSSPacketCount(struct cPort *port, int16_t queue) {
154158
return rte_eth_rx_queue_count(port->PortId, queue);
155159
}

0 commit comments

Comments
 (0)